You are here: Re: session IDs and the like « PHP Programming Language « IT news, forums, messages
Re: session IDs and the like

Posted by Berimor on 11/06/05 02:58

On Sun, 6 Nov 2005 11:09:58 +1300, windandwaves <winandwaves@coldmail.com>
wrote:

> Hi Folk
>
> Forgive me for asking such a basic question... I have a site where I
> want to
> track the user from start till end... To do this, I have setup the
> following structure for each page, referring to startup.php, where the
> session is managed. Can anyone check that I am doing it right. I
> thought I
> was doing it right, but then the site started doing really, really funny
> stuff, basically loosing track of sessions ...
>
> I want my application to be as portable as possible, so I want to
> override
> all the php.ini values that are important.
>
> Thanks in advance (TIA)
>
>
> - Nicolaas
>
>
>
> <?php
> include_once("startup.php");
> if ( !startup( ) ) {
> die("could not load application");
> }
> ...
> ...//page content here
> ...
> echo '<a href="testme.php?'.sid(false).'">link one on the page</a>';
> echo '<a href="testme.php?a=3'.sid(true).'">link two on the page</a>';
> ...
> ...//more page content here
> ...
> ?>
>
>
> /*startup.php file: */
> //function to start session
> function startup() {
> $expiry = 60 * 60 * 24 * 1000;
> ini_set('session.cache_limiter', 'nocache');
> ini_set('session.use_trans_sid', 1);
> ini_set('arg_separator.output', "&amp;");
> ini_set('session.use_cookies', 1);
> ini_set('session.use_only_cookies', 0);
> setcookie("CookieTest", "t"); //set a cookie so next time we know if the
> user can do cookies
> ini_set('session.cookie_lifetime', $expiry);
> session_start();
> }

session_start() should first in output to browser. Try to place
thesetcookie() after session_start().


> //function to include session ID in case they do not accept cookies
> function sid($withamp) {
> if($_COOKIE["CookieTest"] == "t") {
> return '';
> }
> $s = session_id();
> if($s) {
> if($withamp) {
> $v = '&amp;';
> }
> $v .= 'PHPSESSID='.$s;
> return $v;
> }
> }
> /* end of startup.php */
>
>



--
Exact Meta Search | Major Search Engine
http://exactsearcher.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация