Jump to content

Help with defining the session variable


crmamx

Recommended Posts

I am trying to define a session variable where I can save it and use it as the user surfs the site.

 

I need the variable saved as $amano so I can use it in my select from/where statement and to echo within a table.

 

This is a test trying to capture and define the variable and works, but I can't get the variable $amano into the session. If I am then I don't know how to display it.

 

<?php>
session_start(); 
$id = $_POST['amano'];
$_SESSION['amano'] = '$amano';     
             
echo "Pageviews = ". $_SESSION['amano'];  // My effort to see what is happening.
echo "<br />";
echo "AMA # = ". $_POST['amano']; // I have it just like I want it here.
echo "<br />";
echo "Sessions AMA # = ".$_SESSION['amano']; 
?>

 

 

 

Link to comment
Share on other sites

Try this:

 

$_SESSION['amano'] = $_POST['amano'];

 

Make sure you only run that code if $_POST['amano'] is supposed to be stored into the session, otherwise it'll get overwritten.  Then you can access $_SESSION['amano'] on subsequent calls to the script, the same way as you would have used $_POST['amano']

Link to comment
Share on other sites

First of all

$_SESSION['amano'] = '$amano';  // will set the session to the acual word $amano  

 

you should do this

$_SESSION['amano'] = $_POST['amano'];    

to set it

 

if its a number then do this to make sure it IS a number

$_SESSION['amano'] = (int)$_POST['amano'];    

Link to comment
Share on other sites

Works perfect. Thanks.

 

But why am I not able to echo the variable $amamo by itself?

 

<?php>
session_start(); 

$id = $_POST['amano'];
$_SESSION['amano'] = $_POST['amano'];     
//$_SESSION['amano'] = (int)$_POST['amano']; // Do this if number              
echo "Pageviews = ". $_SESSION['amano'];  //Works
echo "<br />";
echo "AMA # = ". $_POST['amano']; // Works
echo "<br />";
echo "AMANO:" .$amano; // This won't work and I have tried single and double 
//quotes, period, no period...everything I can think of to output #amano by itself
echo "<br />";
echo "Sessions AMA # = ".$_SESSION['amano']; // Works
?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.