Page 1 of 1

php java redirect ?

Posted: Fri Apr 08, 2005 1:55 am
by z3phir
hi ! i'm traing to make a redirect using some kind of java detection. here is the code

Code: Select all

<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
    </head>
    <body >
        
        <?
        if ($_REQUEST['done']<>'1')
		{
		?>
			<script type="text/javascript">
			<!--
			window.location = "test.php?java=1&done=1"
			//-->
			</script>
        <?
		}
		?>

        <?
		if (($_REQUEST['java']=='1') and ($_REQUEST['done']=='1'))
		{
		?>
			<script type="text/javascript">
			<!--
			if (screen.width==800||screen.height==600) //if 800x600
				window.location.replace("800.php")
			else if (screen.width==640||screen.height==480) //if 640x480
					window.location.replace("640.php")
				else if (screen.width==1024||screen.height==768) //if 1024x768
						window.location.replace("1024.php")
					else //if all else
						window.location.replace("defaultjava.php") 
			//-->
			</script>
        <?
		}
	    else
		{
			header("Location:nojava.php");
		}
		?>
 
    </body>
</html>
my problem is that it executes the "else" and not the java redirect.
if i eliminate the "else" the script works just fine. any ideeas what i'm doing wrong or any other code to do the same thing ? 10x in advance

i modified the code a bit and it works on Apache/2.0.45 and PHP/4.2.4
the problem is on the latest version of apache and php.

Posted: Fri Apr 08, 2005 2:12 am
by Chris Corbyn
For a start, you can't output anything to the page before header() is sent... That fails immediately.

So putting <script> which shows in the HTML source code, before header() causes errors (try putting error_reporting(E_ALL);) on the top line of you page and it may help ;-)

Posted: Fri Apr 08, 2005 2:16 am
by z3phir
i placed all code corectly is inside the body tags but it dosen't work it executes the else and not the redirect script. i have java activated.
here is the whole page

Code: Select all

<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
    </head>
    <body >
        
        <?
        if ($_REQUEST['done']<>'1')
        {
        ?>
            <script type="text/javascript">
            <!--
            window.location = "test.php?java=1&done=1"
            //-->
            </script>
        <?
        }
        ?>

        <?
        if (($_REQUEST['java']=='1') and ($_REQUEST['done']=='1'))
        {
        ?>
            <script type="text/javascript">
            <!--
            if (screen.width==800||screen.height==600) //if 800x600
                window.location.replace("800.php")
            else if (screen.width==640||screen.height==480) //if 640x480
                    window.location.replace("640.php")
                else if (screen.width==1024||screen.height==768) //if 1024x768
                        window.location.replace("1024.php")
                    else //if all else
                        window.location.replace("defaultjava.php") 
            //-->
            </script>
        <?
        }
        else
        {
            header("Location:nojava.php");
        }
        ?>
 
    </body>
</html>

Posted: Fri Apr 08, 2005 2:38 am
by Chris Corbyn
Where are $_REQUEST['done'] and $_REQUEST['java'] coming from?

Also, the else statement is still wrong - you can't execute a header() command inside the body.

Did you put error_reporting(E_ALL); at the very top?