How would I store this in a session:
<?php
if(isset($_GET['gassearch'])){
echo $_GET['gassearch'];}
else{ echo $_GET['gassearch'] = 'not ordered';}
?>
I need to access this info on another page if it's possible.
Many thanks
| SitePoint Sponsor |
How would I store this in a session:
<?php
if(isset($_GET['gassearch'])){
echo $_GET['gassearch'];}
else{ echo $_GET['gassearch'] = 'not ordered';}
?>
I need to access this info on another page if it's possible.
Many thanks
Just add to $_SESSION['gassearch']
if(isset($_GET['gassearch'])){
$_SESSION['gassearch'] = $_GET['gassearch'];
}
then during user's session you can use $_SESSION['gassearch'] on any page
My project: Open source Q&A
(similar to StackOverflow)
powered by php+MongoDB
Source on github, collaborators welcome!
to extend, add
PHP Code:session_start();
/* this needs to be at the very top of every page you
want to access $_SESSION data */
if(isset($_GET['gassearch'])) {
$_SESSION['gassearch'] = $_GET['gassearch'];
}
echo $_SESSION['gassearch'];
Thanks all for your replies.
I'm trying to get the info out to send in an email but I'm struggling a bit:
This is throwing up an error: Parse error: syntax error, unexpected T_STRINGPHP Code:// multiple recipients
$to = 'example@hotmail.com' . ', '; //
$to .= 'example@hotmail.com';
// subject
$subject = 'Ordered Items';
// message
$message = '
<html>
<head>
</head>
<body>
if(isset($_SESSION['gassearch'])){
echo $_SESSION['gassearch'] = $_SESSION['gassearch'];}
else{ echo $_SESSION['gassearch'] = 'not ordered';}
</body>
</html>
';
// Mail it
mail($to, $subject, $message, $headers);
no wonder
and i think you are a little confused.PHP Code:// message
$message = '<html>
<head>
</head>
<body>'; // come out of the variable here to do if statement
if(isset($_SESSION['gassearch'])){
/* i guess you want the variable in the mail: */
$message .='<p>'. $_SESSION['gassearch'].'</p>';
} else {
$message .='<p>Not Ordered</p>';
}
$message .='</body></html>';
you assign a session in the same way you assign a variable. You also access it the same (essentially).
PHP Code:/* your code */
echo $_SESSION['gassearch'] = $_SESSION['gassearch'];}
# this is wrong, it should be:
$_SESSION['my_session'] = 'some data'; // in this example you want to use $_GET['gassearch'];
echo $_SESSION['my_session'];
// echos some data
// and don't forget you *must* have session_start();
// at the very top of the page or it won't work.
Bookmarks