Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Software & Web Development
Development
[php] redirection and session start
b3t4
Hey ppl,
What i need to do is to start a session and be able to redirect a user on the same php page.
It appears that in php it requires that session_start() be the first thing on the page AND header() has to be the first thing on the page.
<?php session_start();
//other code goes here
//then try to redirect
header("Location:somepage.php");
?>
Therefore if i try to do the above i get the warning message --"blah blah .....headers already sent ....blah blah"
Is there anyway of doing both on the same page????
Any help or ideas appreciated,
A
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
dahamsta
What's the other code b3t4? I can't check now because my development machine is offline, but header() should work /unless/ something has been output, and session_start() doesn't actually output anything, it simply uses setcookie() internally to set the session id. Can you post the complete code?
As a workaround, you could output a meta refresh tag:
<meta http-equiv="refresh" content="0; url=/blah">
adam
Talliesin
I don't know about PHP, but certainly in many such HTTP scripting systems you can't send a header if you've sent anything that isn't in a header (that is, if you've sent any text).
Make sure that this isn't the case in your code.
Gavin
i think there is also an option in php.ini that will automaticly turn on session variables..
Gav
The Corinthian
Do not echo/print anything to your page before adding the redirect (which is in fact a HTTP header). Header commands (such as Location, Content-Type, etc.) can only be used
before
the body of your page.