Re: Session problems

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

 




Don't use session_register()

It was only needed way back when in PHP3 (?)

Simplify your test until it "works" -- Then start adding the other stuff in.

Are you *SURE* you are calling session_start() on the page that gets the
POST?

I think you need to call session_name() *BEFORE* session_start() but I
could be wrong about that...

What may be happening is PHP uses the default name to set your cookie to
start with, then you change the session_name() but it's too late, the
cookie already was set.

If you reverse the order in another page, the other page looks for a
cookie name that doesn't exist.

Re-configure your browser to display all the cookies you get.

On Tue, July 12, 2005 6:54 am, Jason said:
> I am having a problem with sessions.  For some reason it keeps creating
> a new session for every page link you click and not using the original
> session created when session_start() gets called.  Below is the code I
> am testing with.
>
> [one.php]
> <?php
>
> $SessionID = md5( uniqid( rand () ) );
>
> session_start();
>
> if( ( !session_is_registered( 'hash' ) ) || ( $_SESSION['hash'] !=
> $_SESSION['chkhash'] ) ) {
> 	session_name( 'prostarinventory' );
>  session_register( 'hash' );
> 	session_register( 'chkhash' );
>  session_register( 'count' );
> 	$_SESSION['hash'] = $SessionID;
> 	$_SESSION['chkhash'] = $SessionID;
> 	$_SESSION['count'] = 1;
> } else {
>  $_SESSION['count']++;
> }
>
> print_r( $_SESSION );
>
> ?>
> [/one.php]
> [test1.php]
> <?PHP
> include 'one.php';
> print_r( $_SESSION );
> ?>
> <form action="test.php" method="post"><input name="test"
> type="text"><input name="" type="submit"></form>
> [/test1.php]
>
> [test.php]
> <?php
> include 'one.php';
> echo "SESSIONS: ";
> print_r( $_SESSION );
> echo "<BR>POSTS: ";
> print_r( $_POST );
> echo "<BR>GETS: ";
> print_r( $_GET );
> ?>
> [/test.php]
>
> Any help is appreciated, so far I have found that if I use the
> include_once 'one.php'; and simply refresh the page sessions work fine,
> but if you call the test1.php then submit the form the session variables
> aren't found in the old session and a new one is being created on the
> server.
>
> --
> Jason G.
>
> "In my opinion anyone
>  interested in improving
>  themselves should not
>  rule out becoming pure
>  energy."
> ~Jack Handley,
>  The New Mexican, 1988.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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