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;
?>
Session Varaiables Problem
Moderator: General Moderators
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
try this:
page1.php:
page2.php:
see if that works. All i did was add session_register()
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;
?>Code: Select all
<?
session_start();
echo $_SESSION['name'];
echo " : ";
echo $_SESSION['pswd'];
?>The page is a multipurpose page so theres no 2nd page but I will post the code below.
I have it working now but I am not sure why, any help would be very appreciated.
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;
}
?>THE SOLUTION!!! :)
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.
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.
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'];
?>
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'];
?>