passing variables to a different page
Moderator: General Moderators
passing variables to a different page
hope anyone can help me, im new to php..
i have 3 pages of php first is the index.php that contains the code :
header("Location:main.php?userName=$_POST[userName]");
i passed the variable userName to the next page main.php and was able to diplay the variable userName.
print "<html><body>Welcome $_GET [userName],<br>\n</body></html>";
my problem is how can i pass the same variable to a next page, i will be using forms on this one, if they click the button the same variable would be submitted to the 3rd php page...
thanks so much in advance....
regards,
nhan
i have 3 pages of php first is the index.php that contains the code :
header("Location:main.php?userName=$_POST[userName]");
i passed the variable userName to the next page main.php and was able to diplay the variable userName.
print "<html><body>Welcome $_GET [userName],<br>\n</body></html>";
my problem is how can i pass the same variable to a next page, i will be using forms on this one, if they click the button the same variable would be submitted to the 3rd php page...
thanks so much in advance....
regards,
nhan
i have tried using session but i have this error :
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /usr/local/apache/login/main.php:6) in /usr/local/apache/login/main.php on line 37
what seems to be the problem....
in my main.php line 37 >>> session_start();
thanks...
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /usr/local/apache/login/main.php:6) in /usr/local/apache/login/main.php on line 37
what seems to be the problem....
in my main.php line 37 >>> session_start();
thanks...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
ob_start() is a band-aid approach to fixing issues with "already sent header" problems. Have a read in our tutorial: viewtopic.php?t=1157
i have tried the ob_start();, but i have to print the session name...
i defined the session as :
$_SESSION['user'] = $_POST['userName'];
on the second page :
ob_start();
print $_SESSION["user"];
but it does not output the value of the userName
on the third page :
i have to display again the the variable userName...
thanks!
i defined the session as :
$_SESSION['user'] = $_POST['userName'];
on the second page :
ob_start();
print $_SESSION["user"];
but it does not output the value of the userName
on the third page :
i have to display again the the variable userName...
thanks!
- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Yes, that looks good. Don't worry, asking questions is how you learn.
What I do out of laziness is write a function like this - I typed this on the fly, so if there are typos excuse me. You can do the same for $_POST obviously.
Or the shorthand.
The idea here is if a $_GET variable is missing, you won't get any error or warning, you will get a default value.
So you could call it like this:
What I do out of laziness is write a function like this - I typed this on the fly, so if there are typos excuse me. You can do the same for $_POST obviously.
Code: Select all
function getVar($GetVariableName, $Default = '') {
if (isset($_GETї$GetVariableName])) {
$result = $_GETї$GetVariableName];
} else {
$result = $Default;
}
return $result;
}Code: Select all
function getVar($GetVariableName, $Default = '') {
return (isset($_GETї$GetVariableName])) ? $_GETї$GetVariableName] : $Default;
}The idea here is if a $_GET variable is missing, you won't get any error or warning, you will get a default value.
So you could call it like this:
Code: Select all
$user = getVar('userName');
$OK = getVar('isOK', false);
Last edited by smpdawg on Sun Feb 27, 2005 10:29 pm, edited 1 time in total.
- smpdawg
- Forum Contributor
- Posts: 292
- Joined: Thu Jan 27, 2005 3:10 pm
- Location: Houston, TX
- Contact:
Was it part of a form that was processed by clicking the submit button? If so, it is likely in the $_POST array. You can find it out quickly by doing this on that page that didn't work.
Then walk through your process and see if the value shows up on the page.
Code: Select all
print_r($_POST);