note 9274 deleted from Session handling functions by sniper
| From: | sniper@php.net | Date: | Mon, 02 Jul 2001 09:52:20 +0000 |
| Subject: | note 9274 deleted from Session handling functions by sniper | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14878@lists.php.net to get a copy of this message | ||
There are many methods to pass values from page to page. Via forms and POST methods, via variables
attached to URL and get method, via cookies and via session variables.
Troubles come when the same variable pass with many methods. I use the following debug code to
assist me on trubles. Hope to be usesfull:
//Call show_debug() to see the variables
function show_debug() {
global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SESSION_VARS, $REQUEST_METHOD ;
reinport_session_vars();
reset($HTTP_GET_VARS);
reset($HTTP_POST_VARS);
reset($HTTP_SESSION_VARS);
reset($HTTP_COOKIE_VARS);
?>
<table border="1">
<tr><td colspan="2"><font color="red">GET
vars</font></td></tr>
<?php
while (list($key, $value) = each($HTTP_GET_VARS)) {
echo "<tr><td><b>$key</b></td>
<td>$value</td></tr>";
}
?><tr><td colspan="2"><font color="red">POST
vars</font></td></tr><?php
while (list($key, $value) = each($HTTP_POST_VARS)) {
echo "<tr><td><b>$key</b></td>
<td>$value</td></tr>";
}
?><tr><td colspan="2"><font color="red">COOKIE
vars</font></td></tr><?php
while (list($key, $value) = each($HTTP_COOKIE_VARS)) {
echo "<tr><td><b>$key</b></td>
<td>$value</td></tr>";
}
?><tr><td colspan="2"><font color="red">SESSION
vars</font></td></tr><?php
while (list($key, $value) = each($HTTP_SESSION_VARS)) {
echo "<tr><td><b>$key</b></td>
<td>$value</td></tr>";
}
?>
<tr><td colspan=2"><font color="red">Misc
vars</font></td><tr>
<tr><td>Request Method</td><td><?php echo $REQUEST_METHOD;
?></td><tr>
</table><?php
}//Debug
//Reinport overiden variables
function reimport_any_vars($arrayname) {
global $$arrayname;
if (!is_array($$arrayname))
return;
reset($$arrayname);
while(list($key, $val) = each($$arrayname)) {
$GLOBALS[$key] = $val;
}
}
// In case a session variable change in the midle off the script
function reinport_session_vars(){
global $HTTP_SESSION_VARS;
reset($HTTP_SESSION_VARS);
while (list($key, $value) = each($HTTP_SESSION_VARS)) {
$HTTP_SESSION_VARS[$key]=$GLOBALS[$key];
}
}