Page 1 of 1
Using variables in header location
Posted: Tue Jul 15, 2003 3:10 am
by deejay
Hi
I'm sure this is something really simple I'm missing but after reading several posts and php.net docs still cant sort it.
Code: Select all
$osCsid = $_SERVERї'osCsid'];
if ($suitable >= 15 ){
header('Location:conditions.php?osCsid='.$osCsid.'');
}
else
echo '<table border="0" width="100%" cellspacing="0"><tr><td class="errorBox"> sorry you are not suitable to receive our product.</td></tr></table>';
}
what is happening is the page is forwarding but the value $osCsid isn't writing at the end, I know this value exists as I can write it on the page.
Thanks you for any tips or help
Posted: Tue Jul 15, 2003 10:32 am
by slick
Use double instead of single quotes, i.e.:
Code: Select all
header("Location:conditions.php?osCsid=$osCsid");
That should do it...
Slick
Posted: Tue Jul 15, 2003 10:51 am
by award
Are you sure you can output $osCsid as I've tried the same code on my machine having changed the $osCsid =$_SERVER['osCsid'] to $osCsid = 'blah' and it works fine...
When using " (double quotes) the string doesn't have to escape to parse any variables in it, that's the difference between it and ' (single quote), which requires escaping as you had done.
Posted: Tue Jul 15, 2003 10:52 am
by deejay
thanks, but it still only enter
?osCsid=
in the URL. funny as I thought it would give the result
as the code doesn't escape to parse.
Thanks any way, i will keep trying things
Posted: Tue Jul 15, 2003 10:58 am
by deejay
sorry Award, i hadnt read your post when i posted last.
Yes I am sure the output of $osCsid returns the value I wish
Posted: Tue Jul 15, 2003 12:20 pm
by hedge
Having a hard time following here. Where are you expecting to see it?
the var will be available to the script that you redirected to (conditions.php) as $_GET['osCsid']
Posted: Tue Jul 15, 2003 2:24 pm
by deejay
Hi Hedge
i'm expecting a value transfered over to the next URL
osCsid=25a91828c35d3d480300e0117d063d29
its a session value that for some reason is dropped on a new page i made for OSC. I was trying to make a patch, it seemed quite straight forward at first, and i'm not at all sure why it wont work.
Posted: Wed Jul 16, 2003 3:48 am
by deejay
the solution was -
firstly i didnt need asign
Code: Select all
$osCsid = $_SERVERї'osCsid'];
as just calling $osCsid was what i needed.
then included it as a field in $_POST as i think the value was getting lost when i posted
Code: Select all
<INPUT TYPE="hidden" SIZE=40 NAME="osCsid" VALUE="<?php echo $osCsid; ?>">
and the called it up inside the if(isset($_POST['submit']) { as
Code: Select all
$osCsid = $_POSTї'osCsid'] ;
and it now works.
Yep its ugly but it works
Posted: Wed Jul 16, 2003 3:56 am
by twigletmac
$_SERVER is for predefined server variables so it was unlikely to have an 'osCsid' element. It is important to use the right superglobal for the job and when it comes to user information - $_GET is from the URL, $_POST is posted form data, $_COOKIE is cookie data and $_SESSION is for information stored in a user session.
Mac