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
?>
Session variables again
Moderator: General Moderators
Tested it with the php code on this forums
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
form.php
admin.php
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.
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>Code: Select all
<?php
session_start();
$password = $_POSTї'password'];
echo $password."<br>";
echo $_SESSIONї'password'];
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>