|
Grigori Rasputin posted:Since zero evalutes to false, it fails even though I can tell the difference between a month that never occurs and a month at the zero position - I just can't test for it. You can test specifically for failure. This will set $i to zero, but the echo will not happen. php:<? $str = 'january is my favorite month'; if(($i = strpos($str, 'january')) === false) echo "not found\n"; ?>
|
# ? Apr 23, 2008 01:40 |
|
|
# ? May 15, 2024 02:52 |
|
Triple-equals signs always weird me out. Since we're evaluating the success/failure of a variable assignment, is your example the same as this?php:<? $str = 'january is my favorite month'; if (!($i = strpos($str, 'january'))) echo "not found\n"; ?>
|
# ? Apr 23, 2008 02:09 |
|
Zorilla posted:Triple-equals signs always weird me out. Since we're evaluating the success/failure of a variable assignment, is your example the same as this? No, because if you are at position 0, it can be evaluated as false, and your expression will return true, and you will see "not found" Learn to love triple equals and it's pal !==
|
# ? Apr 23, 2008 03:00 |
|
Zorilla posted:Triple-equals signs always weird me out. Since we're evaluating the success/failure of a variable assignment, is your example the same as this? It's not the same, because strpos() will find the string successfully and return zero (because the match occurs at offset zero). It's a case where a non-true value does not indicate failure. The triple equals does the same comparison, but only succeeds if the values compared are of the same type. The false keyword is implicitly boolean, so it is like (bool)0. This lets you check if strpos() failed regardless of its return value.
|
# ? Apr 23, 2008 03:03 |
|
So, how would I go about "renting" a php coder? I had a very good idea for my game, but it's way over my head (even if it's not that complicated). I appreciate all the help I've been given but I don't want to be constantly bothering people about every detail. EDIT : put a bid on rentacoder but don't know if anyone will be interested, it's very small, under $35 dollars :| LastCaress fucked around with this message at 12:04 on Apr 23, 2008 |
# ? Apr 23, 2008 11:19 |
|
Are there a limitations to file_get_contents() that I am not aware of? Namely it not accepting urls that are really long (349 characters)? Ed: got it, a space hidden within a single field in the long rear end url. noonches fucked around with this message at 16:18 on Apr 23, 2008 |
# ? Apr 23, 2008 15:38 |
|
Zorilla posted:PHP has powerful functionality for manipulating date and time formats. What is the end goal of this code? I'm parsing an event calender and putting it into the database. The original format is not completely conducive to being machine-readable but I've got a pretty effective strategy in place for parsing it... one day I'm just going to have to buckle and really learn REGEX though. As far as the month bit, I strip out all the date info and pass it to mktime() and then pass the raw time off to the DB. The dates can be in strange formats for multi-date events so I kinda have to make due. If you have any recommendations for date functions outside of date() and mktime() I'd wouldn't mind hearing/reading more about them though. Everyone else: thanks for the === info, I guess I need to read up on operators a little more. So far I really like PHP, after programming in PL/SQL and object-oriented languages for the past few years it's refreshingly powerful without a lot of the excess of something like Java, where it seems like you spend 99% of your time MAKING EVERYTHING A CLASS (which I really enjoy too). Being able to use PEAR and to connect to a DB, query it and spit out the results in under ten lines rules, it's so straightforward. It is really easy to make mistakes though, I'll forget my $ on variables every so often or gently caress up variable case. Any good and simple IDEs that the detect errors? I'm using NotePad++ which is good, but don't mind a few frills like method sensing and whatnot.
|
# ? Apr 23, 2008 17:33 |
|
Grigori Rasputin posted:If you have any recommendations for date functions outside of date() and mktime() I'd wouldn't mind hearing/reading more about them though. strtotime() is an amazingly powerful little function.
|
# ? Apr 23, 2008 17:57 |
|
Oh, another quick one that's more of a general *AMP/database question. Should I store timestamps in the format generated by PHP's mkdate() or MySQL's native date format?
|
# ? Apr 23, 2008 19:33 |
|
Grigori Rasputin posted:Oh, another quick one that's more of a general *AMP/database question. Should I store timestamps in the format generated by PHP's mkdate() or MySQL's native date format? Storing them as the databases' native date format has the advantage that you know it's a date because it says so and not because the program uses it as one.
|
# ? Apr 23, 2008 20:22 |
|
duz posted:Storing them as the databases' native date format has the advantage that you know it's a date because it says so and not because the program uses it as one. Not to mention MySQL's built in date functions that won't work on something that is not a date.
|
# ? Apr 23, 2008 20:28 |
|
I have a general question about arrays and objects. I have been using code igniter a lot lately and it is (in most cases) happy to accept an object as a function input anywhere that it will take an array. I think my code is a bit easier to read using objects instead of arrays. The syntax of arrays always seemed a bit clunky to me. There are a few places where CI will not take an object and only works with arrays so I have had to break out the odd array here and there throughout my code. It has me thinking now about arrays and objects and if I should be using one over the other. I realize objects can hold more data types but I have never built my own object/class. I don't have any class functions inside my objects. I tried in CI once and failed miserably. I don't know if I was doing it completely wrong or if I wasn't following CI's specifications. So my objects just look like arrays for the most part. In fact, anywhere that I was forced to use an array I always change the variable to an object type as soon as I can to continue working with it. Should I be using objects in this manner? I am just using them to store string variables which I pass between functions for the most part. I just think it looks nicer when you define them, and especially when you have to echo them out into your final html.
|
# ? Apr 27, 2008 02:23 |
|
Kaluza-Klein posted:I have a general question about arrays and objects. I have been using code igniter a lot lately and it is (in most cases) happy to accept an object as a function input anywhere that it will take an array. Using objects can help immensely. So you are on the right track, but could get your learn on in the realm of OO. Here is an example of a simple object and how it might be useful. code:
Anyways, there are a billion books out there on OO theory. You don't have to get one that is based on PHP, you can read one that is about Java or even C++ and as long as you understand the theory you can apply it to PHP. As far as CI is concerned, you can make an object behave more like an array in php by having it implement some interfaces (there are also magic methods defined here http://www.php.net/manual/en/language.oop5.magic.php) Here is a simple example. You would probably want to use the __get() and __set() magic methods to make it a little more solid. code:
Before you do any of that though, brush up on some theory.
|
# ? Apr 27, 2008 03:45 |
|
I've just started to look into PHP and I don't have a whole lot of programming experience, just some basic Java background. I'm sure there is a basic solution, so here it goes. I have a $_SESSION['array'] with some basic data in it, and I need to remove one of the entry's completely, and effectively shift everything in the array up to replace it. How would I go about doing this? I haven't provided a lot of detail as I'm sure there is a simple solution to this, however if I have done a lovely job of explaining my problem then I can provide some more of my code and go into it in more detail.
|
# ? Apr 28, 2008 09:29 |
|
sc0tty posted:I've just started to look into PHP and I don't have a whole lot of programming experience, just some basic Java background. I'm sure there is a basic solution, so here it goes. You want array_values() php:<? $my_array = array (0 => 'Mike', 1 => 'Rob', 2 => 'Jeff', 3 => 'Tom'); //do whatever with $my_array[1] and then remove it from the array with unset($my_array[1]) $my_array = array_values($my_array); //Produces array = ([0] => Mike, 1 => Jeff, 2 => Tom); ?>
|
# ? Apr 28, 2008 10:24 |
|
Evil Angry Cat posted:You want array_values() Thanks this is exactly what I was looking for.
|
# ? Apr 28, 2008 13:23 |
|
Got a strange problem I figure you guys can take a crack at. I'm making a real basic file upload utility that uploads an access db that's data is to be imported into a mysql db. I've got the upload utility working for small (< 1MB) files, but when I test in the 5-30MB range nothing happens after post - I simply get a white page with none of my print/echo statements rendering, no errors, no warnings. Anyone have any clues? I have a hidden field for MAX_FILE_SIZE in my form that's plenty large for files of this size as well as upload_max_filesize set to 30MB in php.ini. Is there something I'm overlooking, is this a php bug, what's the deal? I know it has to be possible to upload 30MB files no problem. edit: After prodding it a bit more, it seems as though the POST never even occurs...\ edit 2: I'm a PHP WIZARD!!!!! Solution: Increase post_max_size in php.ini Grigori Rasputin fucked around with this message at 20:28 on Apr 28, 2008 |
# ? Apr 28, 2008 20:07 |
|
Make sure post_max_size in your php.ini is also set appropriately.
|
# ? Apr 28, 2008 20:27 |
|
Don't forget post_max_size as well as any database size limits.
|
# ? Apr 28, 2008 20:27 |
|
Or better yet, put something like this in your .htaccess so you don't change PHP settings globally:code:
Alternatively, you can adjust php.ini settings during the run of a script with ini_set();
|
# ? Apr 28, 2008 21:18 |
|
Begby posted:Using objects can help immensely. So you are on the right track, but could get your learn on in the realm of OO. Woah, thank you Begby. That was very helpful! I gave objects another shot and I have my first CI library up and running! I am now on my second library and I have hit a snag. I tried to do this: php:<? class Listing { public $default->display_type = 'all'; public $default->display_order = 'title'; public function read_uri() { $uri_options = $this->ci->uri->uri_to_assoc(3, $default); bla bla bla } } ?> I imagine there is a good reason I cannot set an object like that at the start? How should I do it instead? Makes me wonder if I can set an array. . . edit: I realize now why having an object declared like that is a bad idea. You could declare a variable $what and then also have a function called $what and that would not be good. You can declare arrays, but only if you use the syntax $bla = array ('huh'), doing $bla[] = 'huh' doesn't work. Now I am a bit confused as to what to keep inside the class and what functions should be by themselves! other people fucked around with this message at 05:25 on May 1, 2008 |
# ? May 1, 2008 01:59 |
|
Kaluza-Klein posted:
I don't know if this is related, but you can't call functions from within a class variable declaration. For instance: php:<? class poop extends woop { var variable1 = "4389348"; var variable2 = "fdjf545478"; var variable3 = trim("fdsuiofd ui fui fds "); function poop() { print "poo lol"; } ?> quote:edit: I realize now why having an object declared like that is a bad idea. You could declare a variable $what and then also have a function called $what and that would not be good. You can declare arrays, but only if you use the syntax $bla = array ('huh'), doing $bla[] = 'huh' doesn't work. When you do $blah[] = "something", the "=" operator kind of works like the ".=" operator. Your basically saying "add this value to the array", When the array has not been set, an error occurs.
|
# ? May 1, 2008 06:33 |
|
Back a whole bunch of pages was the question "How to stop image leeching". Do this;- Compress 1 gig of zeros into a file named "image.jpg.gz". It'll come down to a megabyte. Use url redirect and some magic to serve that as a gzip encoded http stream instead when the referer is all wrong. Being that this satanic son of a bitch memory-murders anything that tries to leech it, the leeching stops very loving quickly. This is also a good way to massacre bots that ignore your robots.txt put in something like dont_download_me_or_yourbrowser_will_die.html which is actually the browser bomb in your robots, and watch as spam spiders die screaming (some, not all, some will use smarter stream tech and not die.) duck monster fucked around with this message at 08:27 on May 1, 2008 |
# ? May 1, 2008 08:25 |
|
duck monster posted:Back a whole bunch of pages was the question "How to stop image leeching". I like this idea
|
# ? May 1, 2008 09:36 |
|
It's like some sort of standards compliant tall.gif
|
# ? May 1, 2008 13:11 |
|
Its a straight out rip of a technique people used to use to rape virus checkers , and particularly mail based ones, many moons ago. Exchange (specifically) based virus checkers used to open up mails and examine them in-situ. The idea of the attack was to exploit the virus checkers ability to open zip files and examined them for virus's. So the trick was to get a gig or so of zeros and compress them to , like , a one meg file, and send it to the server. The server would then take it, open the zip file, and malloc() like an insane bitch to make memory for it, thus rendering itself completely gibberingly brain-dead. Eventually virus checkers got smart and switched to streams based zip processing. Thing is, this attack vector STILL works against browsers and MANY spiders. You basically tell apache to take the gzip file and under NO circumstance open it for sending (because you'll end up raping your own box) , but just send it as the pre gzipped html page. When I first tested it against a known spider, I noticed it accepted gzip html, so I tried it out. As the spider hit, I started pinging it, and watched as it fell for the trap. Very quickly the pings slowed down until after about 2 minutes, it just dropped off. Presumably the spider went catatonic. Its nasty, its brutal, and it serves weblog spammer cunts right.
|
# ? May 2, 2008 18:26 |
|
I was using php code to check if a sent $_GET didn't come from outside of my website. Now I want to do the same thing with $_POST, and I expected the code to work for it, but it doesn't do anything inside the if statement if a $_POST occurred. I tested to make sure this was the case by echoing the sent $_POST outside of the if statement, which works. Here's the code I used to validate a $_GET: code:
LP0 ON FIRE fucked around with this message at 22:19 on May 2, 2008 |
# ? May 2, 2008 22:16 |
|
awdio posted:I was using php code to check if a sent $_GET didn't come from outside of my website. Now I want to do the same thing with $_POST, and I expected the code to work for it, but it doesn't do anything inside the if statement if a $_POST occurred. I tested to make sure this was the case by echoing the sent $_POST outside of the if statement, which works. Hmm, I'm stumped on that one, but as a quick check, try this: php:<?php $tmp = strpos(strtolower($_SERVER['HTTP_REFERER']), 'mywebsite.com'); echo "My test returned: ".$tmp; if ($tmp !== false){ echo $_POST["sentVar"]; }else{ echo "Hey, my test failed! ".$_POST["sentVar"]; } ?>
|
# ? May 2, 2008 22:36 |
|
Lumpy I tried your test and it failed.
|
# ? May 2, 2008 22:40 |
awdio posted:Here's the code I used to validate a $_GET: I thought HTTP_REFERER couldn't be trusted?
|
|
# ? May 2, 2008 23:30 |
|
awdio posted:
Shouldn't referrer handling be done though .htaccess?
|
# ? May 3, 2008 00:05 |
|
fletcher posted:I thought HTTP_REFERER couldn't be trusted? Standish fucked around with this message at 00:16 on May 3, 2008 |
# ? May 3, 2008 00:13 |
|
Zorilla posted:Shouldn't referrer handling be done though .htaccess? Ideally.
|
# ? May 3, 2008 04:20 |
|
I figured out the HTTP_REFERER issue. I don't know if this was obvious to any of you, but when you use $_POST as opposed to $_GET, you actually have to specify the ENTIRE address, not just the file name even if it is in the same directory to be able to send the HTTP_REFERER information and get it back with $_POST. Of course the information for the $_POST will return, but not the HTTP_REFERER.
|
# ? May 3, 2008 06:21 |
|
edit sorry wrong thread.
LP0 ON FIRE fucked around with this message at 18:52 on May 3, 2008 |
# ? May 3, 2008 18:49 |
|
I've got a script that i've got running on a cron schedule. A little while ago, i rewrote the script to also allow it to be run from the web. However, one thing that's screwing up consistently is the file paths. if i call http://www.domain.com/script.php the relative pats in the file are interpreted differently than if it's being called like php -f /var/www/foo/bar/script.php . Is there a reliable check i can perform in my script that will see whether it's being run via the web versus being called from the command line? This way i'll be able to modify the file paths within the file depending on how the script is being run.
|
# ? May 4, 2008 23:25 |
|
Why not just use absolute paths?
|
# ? May 4, 2008 23:38 |
|
Is there some way to use anonymous arrays? For example, echo (array(1,2,3))[1] would output "2".
|
# ? May 5, 2008 03:32 |
|
duz posted:Why not just use absolute paths? because i'm obviously a complete moron. I just assumed that the webserver in parsing the path wouldn't understand /var/www/bla/bla and try and tack that on to the virtual host root path.
|
# ? May 5, 2008 04:16 |
|
|
# ? May 15, 2024 02:52 |
|
xobofni posted:Is there some way to use anonymous arrays? For example, echo (array(1,2,3))[1] would output "2". php:<? echo current(array_slice(array('ZERO','one','two','three','four'),2,1)); ?> Someone with more experience probably knows a better way, though. Edit: if there is no better way, I already have a function laying around that encapsulates that crap: php:<? function anonArrayVal($theArray,$index) { return current(array_slice($theArray,$index,1)); } ?> Munkeymon fucked around with this message at 17:34 on May 5, 2008 |
# ? May 5, 2008 17:30 |