Page 1 of 2

strange header location error

Posted: Sat Jan 10, 2004 10:59 am
by kumarsena
hi,

i ahve the code as below, but instead of redirecting to given url, the script rather reloads the index page where the user makes the selction.. how come. it is working fine on localhost, but not on the server...

any ideas....it was working fine while i was using cookies, but when i moved to sessions it started acting like taht.




<?php

session_start();

header("Cache-control: private"); // IE 6 Fix.


// Get the user's input from the form
$skin = $_POST['skin'];

// Register session key with the value
$_SESSION['name'] = $skin;

header("Location: http://www.domain.tk/welcome.php3");
?>

Posted: Sat Jan 10, 2004 5:29 pm
by Gen-ik
Have you tried removing the first header() statement.. there doesn't appear to be any real need for it and I don't know why it's supposed to be an IE6 fix either, I use IE6 all of the time and have never had to use that 'fix' in any of my code.

Posted: Sat Jan 10, 2004 5:33 pm
by Straterra
That "IE Fix" is in alot of tutorials..

Posted: Sat Jan 10, 2004 5:37 pm
by Gen-ik
True, but there are a lot of things in tutorials which aren't always needed. All I was saying is that I've never needed to use it... and I use IE6 all the time.

Posted: Sat Jan 10, 2004 5:45 pm
by kumarsena
well i ahve tried removing the first header,,,,,

but still same problem....works on localhost....
but if i redirest to the same file on server using full url. it opens the index.html file but the address bar shows ...welcome.php3...now i find that pretty weird...

basically this is my problem:

user goes to index.html chooses a skin. this is saved in a session then the user is redirected to welcome.php3. it worked fine while i was using cookies, but with sessions i cannot get it to work...
any help to solve this problem would help.

Posted: Sat Jan 10, 2004 5:49 pm
by Gen-ik
It might be useful to see some more of your code... now that you've mentioned sessions() you might have a problem with those and not the actual page redirection.

Also when using header() to redirect to your own website pages you shouldn't have to use the full url as it can be used as a relative redirection... ie header("page2.php") or header("../page2.php") and so on.

Posted: Sat Jan 10, 2004 5:53 pm
by kumarsena
well, this is how it goes..

the code on top is the code i use to set the session...the user calls it after choosing the skin on the index.html page. the on every page that i use the skin i include the following script..

<?php

session_start();

header("Cache-control: private"); // IE 6 Fix.


?>



then the following to use the skin

<link rel="stylesheet" href="<? echo $_SESSION['name'];?>" type="text/css">

and thats it...

Posted: Sat Jan 10, 2004 5:55 pm
by kumarsena
i have tried removing the ie fix in both scripts but still same problem..

Posted: Sat Jan 10, 2004 5:56 pm
by kumarsena
in the first bit of code, i was thinking the problem could be that im sending info before im sending the header,,,but i really dont know,,,just a tought

Posted: Sat Jan 10, 2004 6:06 pm
by kumarsena
i tried not using the url but teh relative path instead. but tehn it loads bu the skin is not loaded, which i guess means the session is not set or something..

Posted: Sat Jan 10, 2004 8:54 pm
by Gen-ik
How are you setting your sessions variables? There are two ways of doing it depending if your server has register_globals on or off... that is one possible problem I can think off.

Posted: Sat Jan 10, 2004 9:59 pm
by Pyrite
Don't use the header() function for redirection or the HTML meta tag either.

Use Javascript.

Posted: Sun Jan 11, 2004 12:08 am
by Gen-ik
Pyrite wrote:Don't use the header() function for redirection or the HTML meta tag either. Use Javascript.
Why?

Posted: Sun Jan 11, 2004 5:11 am
by kumarsena
// Register session key with the value
$_SESSION['name'] = $skin

Posted: Sun Jan 11, 2004 8:03 am
by JAM
Gen-ik wrote:True, but there are a lot of things in tutorials which aren't always needed. All I was saying is that I've never needed to use it... and I use IE6 all the time.
The IE6 bug is about messages as "Want to refresh data" and it's likes when presing the back button after submitting a form (as well as issues saving the forms entered data while doing the same).
Yes, might work for you, but you are perhaps 2% of the IE users not affected, so i'd still recommend using it along with other no-caching headers. It's not vital to get things to work, it merely removes certain unwanted sideeffects.
Pyrite wrote:Don't use the header() function for redirection or the HTML meta tag either.

Use Javascript.
Headers works just fine. Why use javascript?

@kumarsena:

Code: Select all

// change 
$_SESSION['name'] = $skin;

header("Location: http://www.domain.tk/welcome.php3"); 

//to
$_SESSION['name'] = $skin;
print_r($_SESSION);
//header("Location: http://www.domain.tk/welcome.php3");
See if at least the $_SESSION gets set.