sudip_dg77 Posted March 25, 2008 Share Posted March 25, 2008 Hi, I have 2 problems: Problem Number 1: Following are my lines of code: <?php session_start(); $uid=$_GET["uid"]; $_SESSION['user'] = $uid; echo "ID : $uid"; header("Location: http://www.dozentips.com/test1/index.php"); $_POST['ref_id']=$uid; ?> But when it is executed the following error is shown: ID : 1977 Warning: Cannot modify header information - headers already sent by (output started at /home/kuuja/public_html/test1/ref.php:6) in /home/kuuja/public_html/test1/ref.php on line 8 What can I do to resolve the above error? It seems that the "header" command to re-redirect the script is not working with "session_start()"?? Problem Number 2: As you will see in my code above the php script redirects the user to a page(http://www.dozentips.com/test1/index.php") which has a HTML form in it. In that HTML form there is a text box field with the name of "ref_id" which should be automatically populated with the value of the variable "$uid" from the above code. But I am not sure I am doing the right thing above to populate the text box field with the value of the variable "$uid". Please can you help? Link to comment https://forums.phpfreaks.com/topic/97720-problem-with-sessions-and-headers/ Share on other sites More sharing options...
therealwesfoster Posted March 25, 2008 Share Posted March 25, 2008 Its because you "echoed" something before the HEADER call. No html or anything (besides php) can be called before the header() functions. Put the "echo" line below your header() function and see if it helps And as for passing a variable to the new page, just use GET variabled. Something like header("Location: http://www.dozentips.com/test1/index.php?ref={$uid}"); Link to comment https://forums.phpfreaks.com/topic/97720-problem-with-sessions-and-headers/#findComment-500035 Share on other sites More sharing options...
sudip_dg77 Posted March 25, 2008 Author Share Posted March 25, 2008 Yes thanks!! It helped. The first problem is solved. But can you help me with the 2nd problem also?? Problem Number 2: As you will see in my code above the php script redirects the user to a page(http://www.dozentips.com/test1/index.php") which has a HTML form in it. In that HTML form there is a text box field with the name of "ref_id" which should be automatically populated with the value of the variable "$uid" from the above code. But I am not sure I am doing the right thing above to populate the text box field with the value of the variable "$uid". Please can you help? Link to comment https://forums.phpfreaks.com/topic/97720-problem-with-sessions-and-headers/#findComment-500037 Share on other sites More sharing options...
cooldude832 Posted March 25, 2008 Share Posted March 25, 2008 what your doing makes no sense you create output but then try and redirect the user It doesn't work that way if you use a header() modification or session_start(); anything that is "server side adjustments" (Sessions, headers) has to happen before any output is sent to the client as this will define the document. Link to comment https://forums.phpfreaks.com/topic/97720-problem-with-sessions-and-headers/#findComment-500038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.