WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Sessions and -enable-trans-sid
Categories : PHP, PHP Configuration, PHP Options and Info, Sessions Update Picture
Jeff Field
Date : Jun 06th 2002
Grade : 2 of 5 (graded 1 times)
Viewed : 7394
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Jeff Field
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

Thanks to all for their help on this. As a follow-up, and after a bunch of playing around with this yesterday,
here's what I've come to learn. Perhaps it will be helpful to others:

With enable-trans-id compiled into PHP and the following directives in php.ini:

session.use_cookies = 0 (PHP uses cookies for sessions - off)
session.use_trans_sid = 1 (PHP uses enable-trans-id for sessions - on)

PHP will automatically append the SID to the end of relative links 100% of the time and will not use cookies no
matter whether the user has cookies enabled for their browser or not.

In the following case (and I presume the more normal way of doing things):

session.use_cookies = 1 (PHP uses cookies for sessions - on)
session.use_trans_sid = 1 (PHP uses enable-trans-id for sessions - on)

PHP will behave the same way for those users that do *not* have cookies enabled for their browser as in the
first example, i.e. append links 100% of the time. However, for those users that have cookies enabled for their
browser, PHP will append the SID to the links only on the first hit to a page. Then, when a user requests the
next page, the auto-rewriting of the URI's stops and cookies are used from that point forward.

Actually, that all makes sense, as the first time a user requests a page, there's no way for PHP to know if the
browser will accept cookies or not. But, on the second request, the browser will send the cookie back to PHP
(along with the appended URI), and PHP from that point on knows that the browser accepts cookies and PHP will
then drop the rewriting of the URI's.

I hope I've got this all correct. The one observation I'd make in regards to using cookies vs. URI's to
maintain the session is this (and please someone correct me if I'm wrong):

If a user does *not* have cookies enabled for their browser, you can lose the session if the user hits an html
page at your site (because PHP will not be involved and will not rewrite the URI's for the .html page). Not
good.

If a user *does* have cookies enabled, they can hit non-PHP pages all they want and when they get back to a PHP
page, the session is still intact.

So, it would seem, while the SID being appended to all URI's should work for all users, non-PHP pages will break
the session (not good). And, as for the cookie method, not all users have cookies enabled for their browser
(also, not good). Therefore, IMO, neither the cookie method or appending the URI method will work as you'd like
100% of the time.

I suppose one thing you could do so that non-PHP pages won't break the session for those users that don't have
cookies enabled would be to just run every page in your site through PHP. That way, the URI's for every page
will be appended with the SID, and maybe that's the way to go.

Anyway, I hope I've got this all right and I hope it helps someone.

Jeff


> -----Original Message-----
> From: Jeff Field [mailto:jfield@aaaq.com]
> Sent: Wednesday, June 05, 2002 11:56 AM
> To: php-general@lists.php.net
> Subject: [PHP] Sessions question (-enable-trans-sid)
>
>
> Hi,
>
> I'm confused about one thing regarding sessions and haven't been able to
> find the definitive answer anywhere. Hopefully, I can here.
>
> There are two ways to enable sessions:
>
> 1) Session ID is passed through cookies
> 2) Session ID is passed through the URL, either done manually or by
> automatic URL rewriting
>
> All the books, tutorials, etc. basically say that cookies are the
> way to go
> but "when users don't have cookies enabled, you have to use the
> URL method".
> Since I have an e-commerce site that is available to the world,
> I'm assuming
> *some* are not going to have cookies enabled. Duh!
>
> So, from what I've read, you can implement the URL method of sessions by
> either manually attaching the session ID to the URLs, or, by compiling PHP
> with enable-trans-sid, which will add the session ID to the URL's
> automatically. The answer that I haven't been able to find is this:
>
> Is this a one or the other proposition? IOW, if I implement sessions with
> cookies, then I can't use the URL method? Or, if I implement the
> URL method
> (with enable-trans-sid), I can't use the cookie method? Or, do
> they work in
> combination. IOW, does PHP automatically know that if a user has cookies
> enabled, PHP will use the cookie method and, when cookies are
> *not* enabled,
> PHP automatically implements the URL method?
>
> Thanks for the help!
>
> Jeff
>



Step by Step installation manual for PHP4.1.x on Windows 2000 based systems running IIS5 using CGI or ISAPI
Categories : PHP, PHP Configuration, PHP Options and Info, Windows 2000
Security, Password lock out after three tries, authorization fails and is logged locked out of account till admin decides he will unlock it.
Categories : Sessions, PHP, MySQL, PHP Options and Info
Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP
Why do i get a "Save As" dialog box when I type in the url of a php3 file
Categories : PHP Configuration, PHP, Apache, Web Servers
This functions compares the current PHP version with a desired version. Because of the 3 tiered version system, a direct compare of a string to phpversion() will not be accurate.
Categories : PHP Configuration, PHP, Variables
How can i see the path of the php3.ini file my php3 uses?
Categories : PHP, PHP Configuration
A beginner's session handling class
Categories : PHP, PHP Classes, Sessions, Beginner Guides
Demo of Alternate Pagination Paradigm (Paging)
Categories : PHP, User Interface, Sessions
Simple PHP program which calls other PHP program you can pass the variables to other PHP program : by Raju
Categories : PHP, PHP Options and Info, Regexps, Program Execution
dl -- load a PHP extension at runtime
Categories : PHP, PHP Functions, PHP Options and Info
XDT Topsite (Gold v1.0)
Categories : Databases, CSS, PHP, HTML and PHP, Sessions
Problem passing session variables
Categories : Sessions, PHP
What is safemode?
Categories : PHP, Installation, PHP Configuration
GuestBook Light - a plug and play application for any website.
Categories : PHP, Complete Programs, Filesystem, Sessions