RE: Sessions: I don't get it!!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Looks like you're making it way more complicated than it needs to be. PHP
will automatically tack on the Session ID tag to your local url's, but only
if it needs to. There is no need to append the SID to url's manually.

Nate

-----Original Message-----
From: Don [mailto:don@xxxxxxxxxxx] 
Sent: Sunday, November 14, 2004 9:54 PM
To: php-general@xxxxxxxxxxxxx
Subject:  Sessions: I don't get it!!

I'd like to do something with sessions that should be easy. But I'm new 
to this, and obviously I'm missing something somewhere...

I want to use cookies if the visitor allows, but tack the session info 
(SID) "get style" on the URL of a linked page *only if* the visitor 
blocks cookies. I've tried a lot of variations, but nothing really 
works. I either  get the entire SID value in the URL (even if cookies 
are accepted), or the SID doesn't show up in the URL, which means it 
works only with visitors who accept cookies.

Below is my most recent attempt. simple.php detects whether the visitor 
accepts cookies by forcing a page reload (my thanks to Chris Shiflett), 
then attempts a redirection, based on whether cookies are accepted. 
Doesn't work.

Anyone got any ideas?

TIA.

-------------------------
<?
# simple.php

ini_set('session.use_trans_sid', 0);
ini_set('session.use_cookies', 1);
ini_set('register_globals', 0);
session_start();

if (! isset($_GET['cac'])) {
 header('Set-Cookie: accept_cookies=yes');
 header('Location: ' . $_SERVER['PHP_SELF'] . '?cac=1');
}

$_SESSION['accepts_cookies'] = isset($_COOKIE['accept_cookies']);

$_SESSION['session_num'] = session_id();

if ($_SESSION['accepts_cookies']) {
 header('location: simple2.php');
}
else {
 header('location: simple2.php?'. strip_tags(SID));
}

die;

?>
--------------------------
<?
# simple2.php
//ini_set('session.use_trans_sid', 0);
//ini_set('session.use_cookies', 1);
//ini_set('session.use_only_cookies', 1);
//ini_set('register_globals', 0);
session_start(); 
?>
<html>
<head>
<title>Processing Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<? echo "Old Session ID: " . $_SESSION['session_num'] . "<br>";
   echo "This Session ID: " . session_id() . "<br>"; 
   echo "SID: " . SID . "<br>"; ?>
<blockquote> 
<?
 echo
?>
</blockquote> 

</body>
</html>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux