Page 1 of 1
Session Varaiables Problem
Posted: Sun Feb 29, 2004 7:35 pm
by Zelpus
I have session_start() at the top of every page and when I goto the next page theres nothing in these varaiables. Is there something else I need to do to register these that I am not doing?
<?php
session_start();
$username= $_POST['logname'];
$_SESSION['name'] = $username;
$userpswd= $_POST['logpswd'];
$_SESSION['pswd'] = $userpswd;
?>
Posted: Sun Feb 29, 2004 9:44 pm
by Illusionist
try this:
page1.php:
Code: Select all
<?php
$username= $_POST['logname'];
$userpswd= $_POST['logpswd'];
session_start();
session_register('name');
session_register('pswd');
$_SESSION['name'] = $username;
$_SESSION['pswd'] = $userpswd;
?>
page2.php:
Code: Select all
<?
session_start();
echo $_SESSION['name'];
echo " : ";
echo $_SESSION['pswd'];
?>
see if that works. All i did was add session_register()
Posted: Sun Feb 29, 2004 11:03 pm
by infolock
another note :
what version of php are you using? Have you checked your global register settings?
Posted: Mon Mar 01, 2004 11:14 am
by Zelpus
The Php version is 4.3.6
The manual says not to use session_register() with the global session variable $_SESSION or am I reading that wrong?
Posted: Mon Mar 01, 2004 11:42 am
by andre_c
Yeah, you don't need session_register(). Can you show the second page code?
Posted: Mon Mar 01, 2004 5:09 pm
by Zelpus
The page is a multipurpose page so theres no 2nd page but I will post the code below.
Code: Select all
<?php
session_start();
if ( isset( $_REQUESTї 'logout' ] ) ) {
session_destroy();
}
if (!isset( $_SESSIONї 'name' ] ) ) {
$_SESSIONї 'name' ] = "NAME";
} else {
if ( isset( $_REQUESTї 'logname' ]) ) {
$_SESSIONї 'name' ] = $_REQUESTї 'logname' ];
}
$page= 1;
}
if (!isset( $_SESSIONї 'pswd' ] ) ) {
$_SESSIONї 'pswd' ] = "PSWD";
} else {
if ( isset( $_REQUESTї 'logpswd' ]) ) {
$_SESSIONї 'pswd' ] = $_REQUESTї 'logpswd' ];
}
$page= 1;
}
?>
I have it working now but I am not sure why, any help would be very appreciated.
THE SOLUTION!!! :)
Posted: Tue Mar 02, 2004 7:49 pm
by cyberhawk
I had the same problem, check your php.ini and locate this:
session.use_trans_sid = 0
and change the 0 to 1:
session.use_trans_sid = 1
Then reboot your puter.
And then your script will work, promise.

Posted: Tue Mar 02, 2004 7:53 pm
by cyberhawk
Ohh.. by the way try this:
First page
<?php
session_start();
$un = "anders";
$_SESSION['uname']=$un;
$_SESSION['ualias']='olle';
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
?>
<p><a href="test4.php">Page 2</a></p>
Second page
<?php
session_start();
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
echo $_SESSION['uname'];
echo $_SESSION['ualias'];
?>