note 53985 added to ref.session
| From: | razvan_bc at yahoo dot com | Date: | Mon, 20 Jun 2005 09:47:57 +0000 |
| Subject: | note 53985 added to ref.session | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90669@lists.php.net to get a copy of this message | ||
Hi! This is a simple tutorial about how session function works
GET all files from here http://3xpectmore.com/freescripts/session.zip
OR
Files:
#############
******************
index.php
******************
------------------------------
<?php
session_start();
if(isset($_SESSION))
foreach($_SESSION as $ch => $vl)
{
$savesession[$ch]=$vl;
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<?php
if(isset($savesession))
{
foreach($savesession as $ch => $vl)
{
echo("key: ".$ch. " value:".$vl."<br>");
}
}
?>
<FORM METHOD=POST ACTION="chsession.php?url=index.php">
key<INPUT TYPE="text" NAME="key"> value<INPUT
TYPE="text" NAME="value"><BR>
<INPUT TYPE="submit" value="go">
</FORM>
</BODY>
</HTML>
------------------------------
Notes :
1.this script will show you all values of $_SESSION array.
2.from here you can set session values like
key : whitehouse value: bush (this is meaning
$_SESSION['whitehouse']='bush';)
and we will send these variables to chsession.php
#############
******************
chsession.php
******************
------------------------------
<?php
// put/change a new key session's value
// (key,value,url)
//_session["key"]=$value
// redirection to $url
if( (isset($key)and ($key!=null) )and( isset($value)and ($value!=null) ) )
{
session_start();
foreach($_SESSION as $ch => $vl)
{
$savesession[$ch]=$vl;
if(isset($_SESSION[$ch]))
unset($_SESSION[$ch]);
}
$savesession[$key]=$value;
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM NAME="f1" METHOD=POST ACTION="chsession2.php?url=<?= $url ?>">
<?php
if( (isset($key)and ($key!=null) )and( isset($value)and ($value!=null)) )
{
foreach($savesession as $ch => $vl)
{
echo('<INPUT TYPE="hidden" NAME="'.$ch.'"
value="'.$vl.'">');
}
}
?>
<INPUT TYPE="submit">
</FORM>
<SCRIPT LANGUAGE="JavaScript">
<!--
document.f1.submit();
//-->
</SCRIPT>
</BODY>
</HTML>
------------------------------
Notes:
now will put all _SESSION values in a new array named $savesession and will destroy old _SESSION
's values
(here unset($_SESSION[$ch]); )
then will redirect page to chsession2.php
#############
******************
chsession2.php
******************
-----------------------------
<?php
session_start();
foreach($_POST as $ch => $vl)
{
$_SESSION[$ch]=$vl;
}
header("Location: ".$url);
exit();
?>
------------------------------
Notes:
here we will save new _SESSION values
and will redirect to index.php
To test this script ..input values:
key : monitor value:lcd
then
key : whitehouse value:georgebush
now try
key : monitor value:clasic
what you see there? the same key's value was replaced with a new value!
GREAT!
© you can use this script,modify,sell and more
Thanks for you read all this stuff! ,
xpectmore @ scriptlance.com(the best freelance website on the world)
3xpectmore.com 01:30 AM gmt+2 ,Thuesday June,21 Romania
Special thanks to Php team , zend , apache, linux
----
Manual Page -- http://www.php.net/manual/en/ref.session.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53985
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53985&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53985&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53985&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53985&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+53985&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53985&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53985&report=yes
Search -- http://master.php.net/manage/user-notes.php