Using variables in header location

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

Post Reply
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Using variables in header location

Post 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>';

  &#125;
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
slick
Forum Newbie
Posts: 3
Joined: Wed Jun 18, 2003 11:52 am
Location: Ireland

Post by slick »

Use double instead of single quotes, i.e.:

Code: Select all

header("Location:conditions.php?osCsid=$osCsid");
That should do it...
Slick
User avatar
award
Forum Newbie
Posts: 13
Joined: Tue Jul 15, 2003 10:45 am
Location: Wakefield, UK
Contact:

Post 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.
Last edited by award on Tue Jul 15, 2003 10:59 am, edited 1 time in total.
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Post by deejay »

thanks, but it still only enter
?osCsid=
in the URL. funny as I thought it would give the result

Code: Select all

.php?osCsid=$osCsid
as the code doesn't escape to parse.

Thanks any way, i will keep trying things
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Post 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
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post 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']
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Post 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.
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Post by deejay »

the solution was -

firstly i didnt need asign

Code: Select all

$osCsid = $_SERVER&#1111;'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&#1111;'osCsid'] ;
and it now works.

Yep its ugly but it works
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

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