5kyy8lu3 Posted January 6, 2009 Share Posted January 6, 2009 Hi. I'm getting '500 Internal Server Error'. I removed my .htaccess and it's still happening so I'm pretty sure it's not the problem. I'm working on writing scripts to tell browser type and version. I run it on my laptop and I get the 500 error. Same thing when my buddy tries it on his computer. When I run it on my desktop, it works fine. Any ideas? This is what the code looks like: <?php $browser = $_SERVER['HTTP_USER_AGENT']; $targ = "firefox"; //this is the browser I'm looking for in the http-user_agent string $slen = strlen($browser); $browser = strtolower($browser); //make everything lower case for ease of searching $pos = strpos($browser, $targ); if ( $pos !== false ) //checks to see if firefox existed in the browser string { $rest = $slen - $pos; //how many characters to take with substr $sbrowser = substr($browser, $pos, $rest); //new string of everything 'firefox' and after $nlen = strlen($sbrowser); $checker = substr($sbrowser, $i, 1); for ( $i = 0; $checker != " "; $i++ ) // not the most efficient method, originally had nothing the loop so it looped only to find the first space { $checker = substr($sbrowser, $i, 1); } $b_and_v = substr($sbrowser, 0, $i ); // takes firefox and the following version number out of the sbrowser string $b_and_v = ucfirst($b_and_v); //capitalize the first character for cosmetics $b_and_v = ereg_replace("[/]", " ", $b_and_v); //remove the slash between the word firefox and the version number echo $b_and_v; } else { echo 'Browser isn\'t firefox.'; } ?> when run on my desktop, the browser outputs this: Firefox 3.0.5 when I run this on my laptop or my buddy's computer, I get the 500 Internal Server Error. (both my laptop and his computer have the same version of firefox as my desktop so I know it's not my code as far as I can tell) any ideas? oh link to the page: www.kloudz.com/bid.php another update: it runs fine on IE and opera on the laptop but not firefox, so maybe it is my code? i'm confused, I didnt' think it was physically possible for me to write code that would throw a 500 error Link to comment https://forums.phpfreaks.com/topic/139642-solved-500-internal-server-error/ Share on other sites More sharing options...
xtopolis Posted January 6, 2009 Share Posted January 6, 2009 I would say the error is in your for loop. It should probably be a while loop... however IMO your whole method is unorthodox. Link to comment https://forums.phpfreaks.com/topic/139642-solved-500-internal-server-error/#findComment-730642 Share on other sites More sharing options...
5kyy8lu3 Posted January 6, 2009 Author Share Posted January 6, 2009 I would say the error is in your for loop. It should probably be a while loop... however IMO your whole method is unorthodox. well it was alot different from when I first uploaded it, I kept changing everything around, trying different things to try to figure out why it won't work but here's more of what it was originally like: <?php $target = "firefox"; $browser = strtolower($_SERVER['HTTP_USER_AGENT']); $pos = strpos($browser, $target); if ( $pos !== false ) { $remaind = strlen($browser) - $pos; $sub_browser = substr($browser, $pos, $remaind); $i = 0; while ( substr($sub_browser, $i, 1) != " " ) { $i++; } $brow = ereg_replace("[/]", " ", ucfirst(substr($sub_browser, 0, $i ))); echo $brow; } else { echo 'Browser is not firefox.'; } ?> and i know this isn't a clean method of doing this, i'll eventually change it to a function so I can call it from anywhere but I'm new to php so if you have a better way of extracting the browser and version number out of the $_SERVER['HTTP_USER_AGENT'] please fill me in oh and even if the error was in my loop, I still won't understand why it works 100% on all browsers on my desktop but it only works in IE and opera (but not firefox) on my laptop (and both computers have identical versions of each browser) here's a screenshot of the page working fine on my desktop: but when I run it on my laptop I get the 500 Internet Server Error, this is really bugging me Link to comment https://forums.phpfreaks.com/topic/139642-solved-500-internal-server-error/#findComment-730652 Share on other sites More sharing options...
5kyy8lu3 Posted January 6, 2009 Author Share Posted January 6, 2009 but when I run it on my laptop I get the 500 Internet Server Error, this is really bugging me i pulled the logs, here is what I found, anyone know what this means? [06/Jan/2009:00:58:03 -0500] "GET /bid.php HTTP/1.1" 200 111 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 (.NET CLR 3.5.30729)" 76.92.233.52 - - [06/Jan/2009:00:58:04 -0500] "GET /favicon.ico HTTP/1.0" 404 161 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 (.NET CLR 3.5.30729)" UPDATE: ok so I realized that I had the code correct for pulling Firefox and the version number out but I didn't take into effect that part being at the very end of the agent string and since I used a " " space as the condition it went into an infinite loop. added an if clause to check against $i being equal to the length of the string to break out if it is. Link to comment https://forums.phpfreaks.com/topic/139642-solved-500-internal-server-error/#findComment-730656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.