Forum Moderators: coopster

Message Too Old, No Replies

session_register

         

FayeN

5:27 am on Nov 11, 2003 (gmt 0)

10+ Year Member



This is the code for the first page

<?php
session_start();

session_register('session_var');
?>

<html>
<head><title> Testing Sessions Page 1 </title> </head>
<body>
<?php

<form action = 'sessionTest2.php' method = 'post'>
<input type = 'text' name = 'form_var' value = 'testing'>
<input type = 'submit' value = 'go to next page'>
</form>";

?>
</body>
</html>

This is the code for the second page

<?php
session_start();
?>

<html>
<head><title> Testing Sessions page 2 </title></head>
<body>
<?php

echo "session_var = $session_var<br>\n";
echo "form_var = $form_var<br>\n";
?>
</body>
</html>

The end result is

session_var =
form_var =

the variable is not showing up
Any ideas?

jatar_k

5:33 am on Nov 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try this way

echo "form_var = ",$_POST['form_var'],"<br>\n";

for the session var you need to assign a value to it, something like

$_SESSION['session_var'] = "this is the value";

it looks like register_globals is turned off (which is a good thing) so you have to use the superglobal array name to access the variables within.

see here
PHP Predefined Variables [php.net]

jatar_k

5:40 am on Nov 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



also
[ca.php.net...]
If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().

<?php
// Use of session_register() is deprecated
$barney = "A big purple dinosaur.";
session_register("barney");

// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["zim"] = "An invader from another planet.";