Session Varaiables Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zelpus
Forum Newbie
Posts: 5
Joined: Sat Feb 28, 2004 4:53 pm

Session Varaiables Problem

Post 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;
?>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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()
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

another note :

what version of php are you using? Have you checked your global register settings?
Zelpus
Forum Newbie
Posts: 5
Joined: Sat Feb 28, 2004 4:53 pm

Post 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?
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

Yeah, you don't need session_register(). Can you show the second page code?
Zelpus
Forum Newbie
Posts: 5
Joined: Sat Feb 28, 2004 4:53 pm

Post 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&#1111; 'logout' ] ) ) &#123;
		session_destroy();
	&#125;
	if (!isset( $_SESSION&#1111; 'name' ] ) ) &#123;
		$_SESSION&#1111; 'name' ]	= "NAME";
	&#125; else &#123;
		if ( isset( $_REQUEST&#1111; 'logname' ]) ) &#123;
			$_SESSION&#1111; 'name' ]	= $_REQUEST&#1111; 'logname' ];
		&#125;
		$page= 1;
	&#125;
	if (!isset( $_SESSION&#1111; 'pswd' ] ) ) &#123;
		$_SESSION&#1111; 'pswd' ] = "PSWD";
	&#125; else &#123;
		if ( isset( $_REQUEST&#1111; 'logpswd' ]) ) &#123;
			$_SESSION&#1111; 'pswd' ]	= $_REQUEST&#1111; 'logpswd' ];
		&#125;
		$page= 1;
	&#125;
?>
I have it working now but I am not sure why, any help would be very appreciated.
cyberhawk
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2004 7:49 pm

THE SOLUTION!!! :)

Post 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. :D
cyberhawk
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2004 7:49 pm

Post 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'];

?>
Post Reply