|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2002-03-15 14:52 UTC] martin_jones at bigfoot dot com
 The script below works fine on PHP 4.1.1, but fails on 4.1.2.
The script sets two session variables. Only the most recent variable seems to get set, with the previous variable getting reset.
-----Script-----
<html>
<body>
<?php
	session_start();
	$varTest1 = "";
	$varTest2 = "";
	session_register("TEST1");
	session_register("TEST2");
	if (isset($_POST['TEST1'])) {
		$varTest1 = $_POST['TEST1'];
		$_SESSION['TEST1'] = $_POST['TEST1'];
	}
	if (isset($_POST['TEST2'])) {
		$varTest2 = $_POST['TEST2'];
		$_SESSION['TEST2'] = $_POST['TEST2'];
	}
	if (!isset($_SESSION['TEST1'])) {
		$_SESSION['TEST1'] = "NOT SET";
	}
	if (!isset($_SESSION['TEST2'])) {
		$_SESSION['TEST2'] = "NOT SET";
	}
	foreach ($_SESSION as $varKey=>$varValue) echo "$varKey => $varValue</br>";
?>
	<form action="sesstest.php" method="POST">
<?php
	if (isset($_POST['SUBMIT1'])) {
?>
		<input type="text" value="<?php echo $varTest1; ?>" name="TEST1">
		<input type="SUBMIT" name="SUBMIT" value="Form1">
<?php
	} else {
?>
		<input type="text" value="<?php echo $varTest2; ?>" name="TEST2">
		<input type="SUBMIT" name="SUBMIT1" value="Form2">
<?php
	}
?>
	</form>
</body>
</html>
------Script End-------
The script should be saved as sesstest.php
The modules configured are GD and XSLT
If you need more information, please contact me.
--
Martin
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 05:00:02 2025 UTC | 
Using session_start() and setting $HTTP_SESSION_VARS['my_Var'] to any value mays help. Here is my code to use the $_SESSION array : //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ session_start(); if (!isset($_SESSION["count"])) { $HTTP_SESSION_VARS["count"] = 0; } $_SESSION["count"]++; echo $_SESSION["count"]; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PHP Version : 4.1.2 OS : Win2K Server Webserver : APACHE 1.3.22 PHP running as the php.exeI recently upgraded to 4.12 running W98: Apache 1.3.19, Win32 PHP/4.1.3-dev running; reg_globals OFF; trying to work my way through sessions. Yikes!! It is hard to figure how it works or when to use $_SESSION or HTTP_SESSION_VARS, w/ or without session_register(). /* this seems to ~work sort of, maybe... $ship_type = $HTTP_SESSION_VARS['ship_type']; //or with $_SESSION.. which seems to be erratic session_unregister("ship_type"); $ship_type= 'trs'; //$ship_type + 1; session_register("ship_type"); flush(); // This allows other pages to show the revised value via $_SESSION["ship_type"] Now if I could just erase a pair in an array with unset... Keep up the goodwork!