session variables not being passed

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
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

session variables not being passed

Post by Deemo »

Whenever i start a session, the variables i registered are not being passed on to other pages. I made a quick application to test this, and it didnt work. Here is the code for it

sessionTest.php

Code: Select all

<?php
	session_start();
	session_register('session_var');
?>
<html>
<head><title>Test</title></head>
<body>
<?php
	$session_var = "testing";
	echo "<form action = 'sessionTest2.php' method = 'post'>
		<input type = 'text' name = 'form_var' value 'testing'>
		<input type = 'submit' value = 'go'>
		</form>";
?>

</body>

</html>
and for sessionTest2.php:

Code: Select all

<?php
	session_start();
?>
<html>
<head><title>Test</title></head>
<body>
<?php
echo "session_var = $session_var<br>\n";
echo "form_var = $form_var<br>\n";
?>
</body>
</html>
This does not work for some reason. to see the output go to
http://69.138.180.98/AOD/test/sessionTest.php

Thanks in advance
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post by phpcoder »

I think the global variable is off in ur php.ini file
try by using

Code: Select all

$_POST&#1111;'form_var']
[/quote]
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

session_register is depreciated in favour of $_SESSION (presuming you have PHP >= 4.1.0), so try :

Code: Select all

<?php 
   session_start(); 
?> 
<html> 
<head><title>Test</title></head> 
<body> 
<?php 
   $_SESSION['session_var'] = 'testing'; 
   echo '<form action = "sessionTest2.php" method = "post"> 
      <input type = "text" name="form_var" value="testing"> 
      <input type = "submit" value = "go"> 
      </form>'; 
?> 
</body> 
</html>
....

Code: Select all

<?php 
   session_start(); 
?> 
<html> 
<head><title>Test</title></head> 
<body> 
<?php 
echo 'session_var = '.$_SESSION['session_var']."<br>\n"; 
echo 'form_var = '.$_POST['form_var']."<br>\n"; 
?> 
</body> 
</html>
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

yeah, that fixed the problem thanks a lot

the reason my code was "old fashinoned" was because the book i was reading from was pre-4.1.0, but thanks for the update :D
Post Reply