Jump to content

mkosmosports

Members
  • Posts

    196
  • Joined

  • Last visited

    Never

Everything posted by mkosmosports

  1. Hey, I am doing a check to see if a certain value exists in an array. If it does, I want to then get the key for that value. It sounds so simple yet Im struggling with it.. Any ideas? Thanks!
  2. Hello, I have a 'page' parameter in the URL. I dont know whether it will be preceeded by a ? or a &, but I want to take it out and put the result into a variable. Right now Im accomplishing that using simple regex and if/else statements. Im wondering if there is a ready-made php function which would know how to manipulate URL's like that. Thanks. mkosmosports
  3. Ok. Ill keep looking around and let you know when I find something.
  4. Hey, Is there any way to show the number sign of any number (ie. if its positive, show the + before it, if its zero, show nothing and if its negative show -) aside from the obvious if/else condition? Perhaps a built-in function... Thanks in advance. mkosmosports
  5. Hey Thorpe, Thanks for your answer. This is exactly what Im looking for. Nevermind my other question. Thanks again.
  6. Hello, When issuing update or insert sql statements using PDO->execute is there anyway of knowing whether any rows were actually affected? Also, is there anyway execute can return a FALSE boolean? (it says on the www.php.net/pdo site it can, but how?) Thanks. mkosmosports
  7. Below is a tutorial on passing form data to php pages. http://www.w3schools.com/php/php_forms.asp
  8. Thanks for your input everyone. I agree with your example revraz, but what about cases where your not manipulating the values, or the values are not user-inputted, like when using the $_SERVER or $_SESSION superglobals (I shouldnt of used the $_POST example in my intial post)? In those cases, does it really just boil down to preference and coding styles? (rab, it looks like you agree with that) I did read that as well regarding the $_POST superglobal dsaba. (it replaces all dots with underscores) Thanks again.
  9. Hello, Im wondering about the usage of superglobals. Ive noticed a lot of tutorials tend to always put the superglobals variable into another variable. Ex. $testvar = $_POST['testvar']; If youre not planning to manipulate its value, wouldnt it make more sense (and potentially faster because you dont need to define another variable) to always just refer to $_POST['testvar']? Or are there some possible issues in doing this? Im hoping someone could clear this up for me. Thanks! mkosmosports
  10. Thanks a million Barand. Thats just what I need, works great. I was also on the same usort path, but didn't think to use the strtotime like you did.. ???
  11. Hey, Ive got the following md array Array ( [0] => Array ( [id] => 3 [title] => Title [date] => Oct 29 08:11 ) [1] => Array ( [id] => 5 [title] => Title [date] => Oct 29 08:25 ) [2] => Array ( [id] => 6 [title] => Title [date] => Oct 29 08:18 ) [3] => Array ( [id] => 4 [title] => Title [date] => Oct 29 08:16 ) What I want to do is sort the 1st level array by the date in the second level array (with the keys getting reordered accordingly) so this one would read as follows after: Array ( [0] => Array ( [id] => 6 [title] => Title [date] => Oct 29 08:18 ) [1] => Array ( [id] => 5 [title] => Title [date] => Oct 29 08:17 ) [2] => Array ( [id] => 4 [title] => Title [date] => Oct 29 08:16 ) [3] => Array ( [id] => 3 [title] => Title [date] => Oct 29 08:11 ) Any ideas? Thanks!
  12. Youre right skunkbad, my bad, I was too excited to continue coding.. My solution was the same as the one you suggested. Just making sure that after every query issued, I delete that query object, thus freeing up the resources needed to make the next query.
  13. Hey, I want to issue multiple queries in my script using PDO. All of of these queries will either retrieve one row with multiple columns or one row with one column, so I am using either fetch or fetchColumn to get the data. Now, I ran into an error message telling me: "General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll()." If there is only one row being retrieved (and I know this for sure), how is it that unbuffered queries are still active? And whats the most effective way to get around this? I can use fetchAll or loop with fetchColumn or call PDOStatement->closeCursor(); after each query data retrieval statement. Anyone else encounter this? Any advice? Thanks.
  14. *bump bump* I hate to be annoying but Im still struggling with this. Quick recap, I want to allow users to upload images from other web locations to my server. However, they have to be valid gif,jpg or png images and cannot excede 20000 bytes. I've come up with the following test script: $deal_image = trim($_POST['deal_image']); $deal_image_ext = substr($deal_image,-4); $goodimgtypes = array(".gif",".jpg",".png"); if(!in_array($deal_image_ext,$goodimgtypes)) { //only check image url's ending with .png, .gif or .jpg echo 'bad extension'; //invalid image type in url filename exit(); } if (!@get_headers($deal_image,1)) { //only check image url's from which we get http header responses echo 'unable to get headers back, not a valid url'; //unable to get header response back, file is not accessible through http exit(); } $headerarr = get_headers($deal_image, 1); $filesize = $headerarr['Content-Length']; $filetype = $headerarr['Content-Type']; $goodimgtypes = array("image/gif","image/jpg","image/png"); if(!in_array($filetype,$goodimgtypes) || $filesize > 20000) { //only jpg,gif,png and smaller than 20000 bytes echo 'bad filetype or image too big'; //not a valid image type or too big exit(); } $getfile = file_get_contents($deal_image,FALSE,NULL,0,20000); //get 20000 bytes of the image in case fake headers were sent back What I want to do though is make sure the $getfile is indeed a valid/complete image before I put I on my server. Is there a way to do it having the image data inside the $getfile string? Or is this approach just not gonna work? Any advice/input much appreciated! Thanks.
  15. Hey, Im marking this topic unsolved again as I wanted to know if using get_headers to obtain remote file information is really a safe method? What Im doing is basically allowing users to upload an image from a remote web location which has to be jpeg,gif or png and not larger than 20000 bytes. Now, cant the user uploading the file just choose a file which they know will send fake headers back, so for example a file is 2GB and its mpeg, but it sends back headers saying its only 15000 and its a jpg type file? I heard you can conceal php inside valid imagery even. Am I worried for nothing? If Im not, Is there a way to determined if a remote file is TRULY an image (jpg,png,gif) and is under 20000 bytes? Thanks all!
  16. Ive found a solution using the get_headers function which works in php 5 and above. $filename = 'http://images.google.ca/intl/en_ALL/images/images_hp.gif'; $headerarr = get_headers($filename, 1); $filesize = $headerarr['Content-Length']; $type = $headerarr['Content-Type'];
  17. Ive tried that already and get the following error message: Warning: filesize() [function.filesize]: stat failed for http://images.google.ca/intl/en_ALL/images/images_hp.gif in
  18. Thanks rajivgonsalves, I do plan on downloading the image that way, but Im still having trouble validating the image, I dont want it to be be bigger than 20KB and it has to be either a jpg, gif or png file. Im trying exif_imagetype, but it doesnt want to accept urls. Anyone know of a way to validate images residing on other web locations before downloading them? Thanks.
  19. Those tutorials would apply to that as well Man on Scooter. If you can get a handle on retrieving from the mysql db, then you can put the returned values inside the matching value attribute of your input or in between the textarea tags of your form to fill them.
  20. Hey, I want to allow users of my site to be able to upload images from other web locations, to my server. Ive never done this before, but Im assuming I cant use the FILES array here and I should pass the file url through POST or GET, then validate it, then save it to the server using fwrite? Is that a correct approach? Can someone give me some advice or point to me to any good tutorials on doing this? Thanks.
  21. Thanks Barand. I have figured out whats wrong, but I made the mistake of assuming multidimensional sub-arrays dont implode.... ??? Sorry. Somewhere in my script I assigned a string to $mainarr['br']['sumconditions'] as opposed to assigning the string to $mainarr['br']['sumconditions'][], so I was in effect no longer imploding an array.
  22. My apologies. Yes, $mainarr['br']['sumconditions'] is an array and below is the $mainarr array $mainarr = array("boundvalues"=>array(), "br"=>array("sumconditions"=>array(), "resultconditions"=>array()), "pd"=>array("sumconditions"=>array(),"resultconditions"=>array()));
  23. Hey, I tried imploding a column in my MD array like so: implode(" AND ", $mainarr['br']['sumconditions']) but this doesnt work returning a bad arguments error message. Does anyone know how to do this? Thanks. Marek
  24. It seems I have found a stable and solid solution to this. The PDO class. For those interested, this seems like a great solution to bettered performance and the painful security headache which is SQL injection: MySQL 5+ and PHP 5+ is required here.. http://www.php.net/pdo
  25. Hmmm, Ive found some more resources on this and you can prepare statements with bind variables using the following mysqli function: http://us3.php.net/manual/en/function.mysqli-stmt-bind-param.php Based on comments in that manual and some other resources Ive found it seems this is still quite unstable, so I think Im gonna revert back to using mysql_real_escape_string().
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.