Page 1 of 1

Newbie Question-Sessions...can't get the to work

Posted: Mon Oct 07, 2002 10:49 am
by matthiasone
I am tring to run sessions on a set of forms and admin pages on my website. I guess I am confused about where you need to start and restart sessions. I start and register a variable on the main page then when I goto the other page and start the sesion again that variable is not available.

Help

Matt

Posted: Mon Oct 07, 2002 11:02 am
by Zeceer
Since you're not printing any code I'll write the code that is right. Check if you've done this:
session_start(); //In top of every document you will use session
session_register("my_var"); //The name of your variabel.
$my_var = "Hello"; //Sets the variable to Hello
In you're second script you have to remember to use the session_start() since that have to be in every script that are going to use the session you created.

You're second script:
session_start();
echo $my_var
You can also use $HTTP_SESSION_VARS['my_var'] to get the variable.




Remember: It could be your server that is not set right

Posted: Mon Oct 07, 2002 11:31 am
by mydimension
if your php version is 4.1 or newer then use
$_SESSION['var'] = "value";
to set your variables
and $_SESSION['var'] to get the value of your variables. Zeceer's way will work on older versions but since version 4.1 register_globals is default to off so $var will not be the same as $_SESSION['var']

Posted: Mon Oct 07, 2002 11:37 am
by twigletmac
Which ever method you use you will need to put session_start() at the top of each page in which you set or use a session variable. Have a look at http://www.php.net/manual/sv/ref.session.php as well.

Mac

Posted: Mon Oct 07, 2002 1:36 pm
by matthiasone
ok thanks for the suggestions,but the variables still aren't passing

the is the code where the session variables is set

Code: Select all

<?
  require_once("spall_fns.php");
  session_start();
  $_SESSION&#1111;'var'] = $user;

  do_pages($area, $page, $view, $id, $eid, $HTTP_POST_VARS, $mode, $cust);
?>
And here is the it variables is asked for

Code: Select all

session_start();
  echo "u= ".$$_SESSION&#1111;'user'];
...
Anymore ideas?

Matt

Posted: Mon Oct 07, 2002 2:05 pm
by rev
matthiasone wrote: And here is the it variables is asked for

Code: Select all

session_start();
  echo "u= ".$$_SESSION&#1111;'user'];
...
Anymore ideas?

Code: Select all

&lt;?php
session_start();
echo "u=" . $_SESSION&#1111;'user'];
?&gt;
Need only the una dolla'rola. 8O

Posted: Mon Oct 07, 2002 2:50 pm
by matthiasone
that was not the problem..........I removed it with the same affect

Matt

Posted: Mon Oct 07, 2002 3:07 pm
by rev
Which version of PHP are you using?

Code: Select all

&lt;?php
phpinfo();
?&gt;
Also, within the configure script used to configure your install in PHP, do you see the following:

--disable-session

In your php.ini file (if you are using one, phpinfo() will tell you where PHP is looking for one) does PHP have proper access to write to the location specified in 'session.save_path' (defaults to /tmp, windows defaults to c:/temp I believe - but I know very little when it comes Windows).

Posted: Mon Oct 07, 2002 3:17 pm
by matthiasone
I am running PHP 4.1.1 on FreeBBS the save directory is set to "/tmp" and the sessions are enabled

Matt :lol:

Posted: Mon Oct 07, 2002 6:11 pm
by mydimension
well right off the bat i can tell you that you are setting $_SESSION['var'] in the first page and calling $_SESSION['user'] in the next page. try using the same array index, either 'var' or 'user'

Posted: Tue Oct 08, 2002 2:50 am
by twigletmac
On your second page you can also quickly see everything (if anything) in the $_SESSION array by doing:

Code: Select all

echo '&lt;pre&gt;';
print_r($_SESSION);
echo '&lt;/pre&gt;';
On a side note, since you are using PHP 4.1 you can use $_POST instead of $HTTP_POST_VARS.

Mac

Posted: Wed Oct 09, 2002 1:31 pm
by matthiasone
Well, mydimension if I used the same array index that would make things too easy...lol :lol:

anyway.....thanks to all the help I (we) got it working. Thanks

Matt