...

View Full Version : Session cookies



Richard
03-26-2003, 01:07 AM
How do you create session cookies using PHP ?

And will it work if the person's browser blocks normal cookies ?

Rich.

Nightfire
03-26-2003, 01:26 AM
All the info you need on sessions :) (about mid-way down are examples)

http://www.php.net/manual/en/ref.session.php

Richard
03-26-2003, 04:18 PM
:(

I'm not good at these things. Testing at the moment. It did set it once, but on main.php is still said it wasn't set. Then I unset it and set it again, and it didn't set.

main.php:


<?php
if (isset($_SESSION['count'])) { echo "Session on."; };
if (!isset($_SESSION['count'])) { echo "Session off."; };
?>
<br>
<a href="reg.php">Set cookie.</a><br>
<a href="unreg.php">Unset cookie.</a>

reg.php:


<?php
session_start();
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
}
?>
<a href="main.php">Session set. Click here for main area</a>

unreg.php:


<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
unset($_SESSION['count']);
?>
<a href="main.php">Session unset. Click here for main area</a>

:confused:

Nightfire
03-26-2003, 04:29 PM
looks like you forgot to add session_start() on main.php

Richard
03-26-2003, 04:58 PM
Thanks :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum