Jump to content

[SOLVED] 500 Internal Server Error


5kyy8lu3

Recommended Posts

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
Share on other sites

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:proof.jpg

 

but when I run it on my laptop I get the 500 Internet Server Error, this is really bugging me

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.