1

I have 'upgraded' my server and the following doesn't work anymore.

It sits at the top of a page, and is supposed to set some cookies and reload the page with empty query string (and cookies set) if the original URL has the correct query string.

What happens now is that the desired page loads and is then immediately replaced by an attempt to load a non-existent page.

As I said, I reinstalled my server and now the same code works correctly on my production server but not on the reinstalled server. I'm running on Ubuntu 15.04 now. My guess is that I neglected some aspect of php/apache installation, but I really haven't a clue.

Thanks for any help you can give. -- Len

<?php
if ( array_key_exists('rId',$_GET) && $_GET['rId'] == 'auth' ){
     setcookie('authCode',$_GET['authCode']);
     setcookie('rId',$_GET['rId']);
     setcookie('GP_UID',$_GET['GP_UID']);
     if ( array_key_exists('license',$_GET) )
          setcookie('license',$_GET['license']);
     else
          setcookie('license',0);
     $pth = $_SERVER['REQUEST_URI'];
     $pth = substr($pth, 0, strrpos($pth,'/')+1)."index.html";
     $url = $_SERVER['SERVER_NAME'].$pth;
     echo "<!DOCTYPE HTML><html><head><META http-equiv='refresh' content='0;URL=http://" .$url. "'></head></html>";
     return;
     exit;
}
?>       
<html>
<body id="view2">
    <h1> Loaded </h1>
</body>
</html>
LenB
  • 1,126
  • 2
  • 14
  • 31
  • That `exit` is never reached. If the application is exactly the same in both servers, it shouldn't make any difference since the other is working. But you can give a try to remove that `return` and see what happens. – Gustavo Straube Oct 03 '15 at 20:35
  • SAame behavior removing return. The really strange thing (to me) is that even if I use a URL with no query string so the PHP should not be executed, using chrome I get the same behaviour. A very brief display of 'Loaded' and then I am redirected to about:blank. In firefox (on linux with no query string ) it displays: "; return; exit; } ?> Loaded. Loaded. – LenB Oct 03 '15 at 20:46
  • 1
    Was configuration problem. http://stackoverflow.com/questions/17495382/apache-2-server-on-ubuntu-cant-parse-php-code-inside-html-file – LenB Oct 03 '15 at 21:00

1 Answers1

0

I would have put this into a comment, but I cannot do that yet ^^. Nevertheless I am pretty sure, you can solve your problems thatway:

header( 'Location: '.$url); 
die();

Once I needed this type of content output, because I had to POST something somewhere after adding/storing/saving values:

...
<html>
<head>
</head>
<body>      
    <form name='foo' action='<? echo $url; ?>' method=POST>
     <input type=hidden name='bla' value='blubb' />
    </form>
    <SCRIPT FOR=window EVENT=onload LANGUAGE='JavaScript'>
     document.foo.submit();
    </SCRIPT>
</body>
</html>

Then try to quit your PHP like you did or with exit(); or die();

Another thing: Whenever you switch your Server you should check if the $_SERVER[xxxx]-keys are still available and like they have been. I had quite a lot of trouble because sometimes there might be slight differences.

Nibbels
  • 156
  • 10