[php] function for GET/POST with support for proxys & cookies.

Status
Not open for further replies.
Hi there Grigori

Just browsing the forums after registration and I felt over this, while I enjoy a snippet of code that does the job it is supposed to, there are several things in this piece I've spotted to hopefully make the code more clear!

  • Drop the @ from ini_set() and set_magic_quotes_runtime(), as none of these functions ever emits an error, meaning the Engine will have to do some overrides (thats how the error-supression operator is implemented in Zend) which we can skip for performance
  • The cURL extensin in PHP does not depend or use the session extension at all, meaning the call to session_save_path() and the ini change of session.gc_probability are useless
  • You have a typo, $cookiejar should be $cookie, or the otherway around in the code
  • The random values: '10000000000' & '99999999999' are both above the signed 32 bit integer size (2147483647), meaning that on x86 systems that doesn't support the C99 feature "long long", or on Windows where integers always are 32bit (the internal datatype for storing the integer is "long", not an "__int64" for portability and compatiblity reasons as of current), meaning they will be normalized or converted into a float, which potentially could mean that the call would be executed as the following: rand(2147483647, 2147483647) which always would equal to 2147483647 ofcourse. I would suggest you use the Mersenne Twister randomization algorithm (the mt_rand functions), that also automatically seeds the randomizer and ofcourse lowering those numbers to be 32bit compatible.
    [*]The global statement 'global $cookie;' should be inside a function declaration, otherwise it would emit a compile error
    [*]You use a @ at the fclose() call but not @fopen() call, it should be the otherway around, but to simplify creating a new temporary file you might want to use tempnam() instead.
    [*]You have another typo, $proxyx should be $proxy
    [*]And last I spot you use unlink() after the return statement, this will never get executed as when you hit a return statement, the scope changes and stops executing, so that needs to be before the return statement, the @ is perfectly fine in this situration as it may emit a file system error


Hope it was helpful!
 
just going to say thanks to both of you, don't ave much o input on this but I did learn a few things from reading through this thread :p
 
Status
Not open for further replies.
Back
Top