strange header location error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

kumarsena
Forum Newbie
Posts: 18
Joined: Mon Oct 20, 2003 7:18 am
Contact:

strange header location error

Post 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");
?>
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

That "IE Fix" is in alot of tutorials..
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
kumarsena
Forum Newbie
Posts: 18
Joined: Mon Oct 20, 2003 7:18 am
Contact:

Post 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.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
kumarsena
Forum Newbie
Posts: 18
Joined: Mon Oct 20, 2003 7:18 am
Contact:

Post 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...
kumarsena
Forum Newbie
Posts: 18
Joined: Mon Oct 20, 2003 7:18 am
Contact:

Post by kumarsena »

i have tried removing the ie fix in both scripts but still same problem..
kumarsena
Forum Newbie
Posts: 18
Joined: Mon Oct 20, 2003 7:18 am
Contact:

Post 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
kumarsena
Forum Newbie
Posts: 18
Joined: Mon Oct 20, 2003 7:18 am
Contact:

Post 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..
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Don't use the header() function for redirection or the HTML meta tag either.

Use Javascript.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Pyrite wrote:Don't use the header() function for redirection or the HTML meta tag either. Use Javascript.
Why?
kumarsena
Forum Newbie
Posts: 18
Joined: Mon Oct 20, 2003 7:18 am
Contact:

Post by kumarsena »

// Register session key with the value
$_SESSION['name'] = $skin
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
Post Reply