Ask about general coding issues or problems here.
Moderators: macek, egami, gesf
by jbn » Thu Jan 09, 2003 8:49 am
my friend is coding a database and has some problems
with sessions/session id's etc.. can anyone write some examples
how to make this work with sessions?
-
jbn
- New php-forum User

-
- Posts: 4
- Joined: Sun Dec 29, 2002 10:32 am
- Location: Sweden
by WiZARD » Sun Jan 12, 2003 6:17 am
<?
unset($s);
session_start();
session_register("s");
if (isset($c) && $c=='clear') {
unset($s);
header("Location: sess.phtml");
echo "clear...";
exit;
}
echo "<a href=sess.phtml>Reload</a><p>";
echo "<a href=sess.phtml?c=clear>Clear</a><p>";
if (!isset($s['count'])) {
$s['count']=1;
}
else $s['count']++;
echo "You are loaded this page: $s[count]<p>";
if (strlen($name)>1) $s['name']=$name;
if (!isset($s['name']))
echo "You are new user. Type your name please:
<form action=sess.phtml><input type=text name=name>
<input type=submit></form>";
else
echo "You registered: $s[name]";
?>
-

WiZARD
- Moderator

-
- Posts: 1257
- Joined: Thu Jun 20, 2002 10:14 pm
- Location: Ukraine, Crimea, Simferopol
-
by WiZARD » Sun Jan 12, 2003 6:20 am
<?
// Before use this script create tmp directory
session_id("0123456789abcdef0123456789abcdef");
session_start();
session_register("flag");
if (!isset($flag)) $flag=0;
switch ($c) {
case "":
echo "FLAG=$flag <a href=$PHP_SELF?c=clear>Clear</a>
<form action=$PHP_SELF>
<input type=hidden name=c value='submit'>
<input type=submit>
</form>";
break;
case "clear":
$flag=0;
header("Location: $PHP_SELF");
break;
case "submit":
if ($flag==0) {
sleep(5);
$flag=1;
srand ((double) microtime() * 1000000);
$filename= "tmp/".rand(0,9999).".php-test";
fclose(fopen($filename,"w+"));
header("Location: $PHP_SELF");
}
else
echo "FLAG is not zero.";
break;
}
?>
-

WiZARD
- Moderator

-
- Posts: 1257
- Joined: Thu Jun 20, 2002 10:14 pm
- Location: Ukraine, Crimea, Simferopol
-
Return to PHP coding => General
Who is online
Users browsing this forum: Bing [Bot] and 3 guests