Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP Session Problem

Nick Young
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi All,

I am trying to get to grips with PHP Sessions. I have a very simple
logon script that works fine so long as the client allows cookies.
However when they have cookes turned off (and I know some of them will
do) it dosnt work. I have 2 simple scripts below for testing that dont
work. I have tried various settings such as:

ini_set('session.use_trans_sid', false); AND
ini_set('session.use_trans_sid', true);
ini_set("session.use_cookies",0);
session_register("logged");
etc...

None seem to have any affect. The scripts I use for testing are below.
When run with cookies disabled the page2 comes up with the error
"Undefined index: logged .........". Am I being stupid here? Can
anyone point out what I am doing wrong?

----------------------------

page1.php

<?php
session_start();
session_set_cookie_params(0);
$_SESSION['logged'] = 1;
echo $_SESSION['logged'];
?>

page2.php

<?php
session_start();
echo $_SESSION['logged'];
?>

---------------

Cheers,

Nick

Moxley Stratton
Guest
 
Posts: n/a
#2: Jul 17 '05

re: PHP Session Problem


Nick Young wrote:[color=blue][color=green]
> > None seem to have any affect. The scripts I use for testing are below.[/color]
> When run with cookies disabled the page2 comes up with the error
> "Undefined index: logged .........". Am I being stupid here? Can
> anyone point out what I am doing wrong?[/color]

You have to hyperlink to page2 from page1 for the trans_sid to work. Are
you doing that?

page1.php
<?php
ini_set('session.use_trans_sid', true);
session_start();
<snip>
?>
<a href="page2.php">page2</a>

When you run page1.php, look at the source code from your browser to see
the URL of the link. Has it been changed to something like this:
<a href="page2.php?SID=a10921830a9019283">page2</a>

Starting with a fresh browser, you should always see this the first time
page1.php is loaded, regardless whether cookies are enabled.

---
Moxley
moxleystratton.com
Nick Young
Guest
 
Posts: n/a
#3: Jul 17 '05

re: PHP Session Problem


Hi,

Yep I am doing that but unless I do

<a href="page2.php<?php echo SID ?>">page2</a>

it wont pass the SID around. I have tried adding
ini_set('session.use_trans_sid', true); which dosnt seem to have made
any difference. I am wondering if it is my installation gone corrupt!!!

Cheers,
Nick

Moxley Stratton mumbled on about the following on 22/05/2004 18:20:[color=blue]
> Nick Young wrote:
>[color=green][color=darkred]
>> > None seem to have any affect. The scripts I use for testing are[/color]
>> below. When run with cookies disabled the page2 comes up with the
>> error "Undefined index: logged .........". Am I being stupid here?
>> Can anyone point out what I am doing wrong?[/color]
>
>
> You have to hyperlink to page2 from page1 for the trans_sid to work. Are
> you doing that?
>
> page1.php
> <?php
> ini_set('session.use_trans_sid', true);
> session_start();
> <snip>
> ?>
> <a href="page2.php">page2</a>
>
> When you run page1.php, look at the source code from your browser to see
> the URL of the link. Has it been changed to something like this:
> <a href="page2.php?SID=a10921830a9019283">page2</a>
>
> Starting with a fresh browser, you should always see this the first time
> page1.php is loaded, regardless whether cookies are enabled.
>
> ---
> Moxley
> moxleystratton.com[/color]
Chung Leong
Guest
 
Posts: n/a
#4: Jul 17 '05

re: PHP Session Problem



"Nick Young" <nick_young@talk21.com> wrote in message
news:c8nrkk$ktj$1@titan.btinternet.com...[color=blue]
> Hi All,
>
> I am trying to get to grips with PHP Sessions. I have a very simple
> logon script that works fine so long as the client allows cookies.
> However when they have cookes turned off (and I know some of them will
> do) it dosnt work. I have 2 simple scripts below for testing that dont
> work. I have tried various settings such as:
>
> ini_set('session.use_trans_sid', false); AND
> ini_set('session.use_trans_sid', true);
> ini_set("session.use_cookies",0);
> session_register("logged");
> etc...[/color]

You can't change use_trans_sid using ini_set(). It has to be set in php.ini.


Closed Thread