Session variables again

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
vvume
Forum Newbie
Posts: 2
Joined: Thu Jul 17, 2003 7:55 pm

Session variables again

Post by vvume »

Must be sounding cliche or dumb asking about Php session variables (tons must have brought up the problem).

Running Apache2/php 4.3.2 experimental/windows xp sp1

I have register_globals turned on. I still had problems with creating session variables. So I used the alternate method suggested (with globals turned off) and I am still not able to propagate session variables across different php pages. Can someone tell me what I am doing wrong (register_globals is still turned ON):

Form.html (I accept a simple password)
==========================
<html>
<body>
<form name="form1" method="post" action="login.php">
<p><input type=password name=password>
<p><input type=submit name=submit value=Submit>
</form>
</body>
</html>

Login.php (get the password and sets a session variable
====================================
<?
session_start();

$password = $_POST['password'];

echo "<p>" . $password;

$_SESSION["password"] = $password;
//session_register("password"); //Tried this one too, no luck

echo "<p>" . $_SESSION["password"]; //works OK
?>

admin.php (another php code trying to get the password)
====================================
<?
session_start();

$password = $_SESSION["password"];
echo "<p>" . $password; //Nothing is printed out

?>
vvume
Forum Newbie
Posts: 2
Joined: Thu Jul 17, 2003 7:55 pm

Tested it with the php code on this forums

Post by vvume »

To double check I used the php test pages on session variables (page1.php, page2.php, page3.php, etc...) and tried. The values DID NOT propogate.. Looks like something is very fishy about apache2 / php 4.3.2 combo on windows xp. Any suggestions?
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post by pistolfire99 »

form.php

Code: Select all

<?php
session_start();
session_register("password");
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="admin.php">
  <p>
    <input name="password" type="password" id="password">
  Password</p>
  <p>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="Submit2" value="Reset">
</p>
</form>
</body>
</html>
admin.php

Code: Select all

<?php
session_start();
$password = $_POST&#1111;'password'];
echo $password."<br>";
echo $_SESSION&#1111;'password'];
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
This works for me, give it a try and see if it works for you. If it does, then adjust the code for your needs.
Post Reply