469,590 Members | 2,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

DIssapearing/reappearing Session variables

Hello,

Thought I'd try this forum as I got some useful help from here before.

Anyway, this is the problem; I have a simple authorisation script (in
PHP):

www.multidome.co.uk/test/authorisation.txt

It works great locally but when I upload it no longer works well; the
problem is that it takes me to the login page whenever I move forward
in the photo gallery; see :

www.multidome.co.uk/test/gallery.php (Username= test; Password=
test)

Sometime, you just need to refresh the login page to be logged you
back in! I think it has something to do with the $authdata session
variable.

Does anybody know what might cause this? I think it might be the same
problem as this:

http://www.thescripts.com/forum/thread9377.html

Thanks.

Duncs

The code for all the php pages can be seen by changing the .php
to .txt, i.e:

www.multidome.co.uk/test/gallery.txt
www.multidome.co.uk/test/authorisation.txt
www.multidome.co.uk/test/store.txt
www.multidome.co.uk/test/getpicture.txt

Apr 9 '07 #1
7 1354
dangerd napisał(a):
Hello,

Thought I'd try this forum as I got some useful help from here before.
Duncs

The code for all the php pages can be seen by changing the .php
to .txt, i.e:
Hello, first of all
http://www.multidome.co.uk/test/authorisation.txt
is wrong - you should call session_start() before sending any data to
the browser (at the beggining of your scripts).
Write it for example one line after error_reporting (null);
(and remove it from auth() function).

Secondly, don't use session_register, just write anything to $_SESSION
(if you are using PHP 4.1 or later).
--
Wiktor Walc
http://phpfreelancer.net
Apr 9 '07 #2
On Apr 9, 8:52 pm, iktorn <s...@phpfreelancer.netwrote:
dangerd napisał(a):
Hello,
Thought I'd try this forum as I got some useful help from here before.
Duncs
The code for all the php pages can be seen by changing the .php
to .txt, i.e:

Hello, first of allhttp://www.multidome.co.uk/test/authorisation.txt
is wrong - you should call session_start() before sending any data to
the browser (at the beggining of your scripts).
Write it for example one line after error_reporting (null);
(and remove it from auth() function).

Secondly, don't use session_register, just write anything to $_SESSION
(if you are using PHP 4.1 or later).

--
Wiktor Walchttp://phpfreelancer.net
Thanks for the help Wiktor,
>is wrong - you should call session_start() before sending any data to
the browser (at the beggining of your scripts).
Write it for example one line after error_reporting (null);
(and remove it from auth() function).
The point of having it inside the function is to only start the
session if a session has not already been started. With that in mind,
do you still think I should take it out of the function?

Duncs

Apr 9 '07 #3
On Apr 9, 8:52 pm, iktorn <s...@phpfreelancer.netwrote:
dangerd napisał(a):
Hello,
Thought I'd try this forum as I got some useful help from here before.
Duncs
The code for all the php pages can be seen by changing the .php
to .txt, i.e:

Hello, first of allhttp://www.multidome.co.uk/test/authorisation.txt
is wrong - you should call session_start() before sending any data to
the browser (at the beggining of your scripts).
Write it for example one line after error_reporting (null);
(and remove it from auth() function).

Secondly, don't use session_register, just write anything to $_SESSION
(if you are using PHP 4.1 or later).

--
Wiktor Walchttp://phpfreelancer.net
Hello,

I got rid of the session_register() and the problem persists. I think
what is happening is that the $_SESSION[$authdata] (I took your
advise on board) dissapears after five or so refreshes but then
reappears after another refresh. There does not seem to be a pattern
on the number of refreshes it takes for $authdata to dissapear.
Strange...

Duncs

Apr 9 '07 #4
dangerd napisał(a):
On Apr 9, 8:52 pm, iktorn <s...@phpfreelancer.netwrote:
>dangerd napisał(a):

Hello,

I got rid of the session_register() and the problem persists. I think
what is happening is that the $_SESSION[$authdata] (I took your
advise on board) dissapears after five or so refreshes but then
reappears after another refresh. There does not seem to be a pattern
on the number of refreshes it takes for $authdata to dissapear.
Strange...

Duncs
There is always some reasonable solution for such problems ;)

In http://www.multidome.co.uk/test/gallery.txt authorisation.php
is included afer DOCTYPE declaration, therefore session_start()
isn't called at the beginning of the script and your session is being
lost (if you don't have some output buffering turned on).

The proper way of using session is:

<?
//must be called on every page
session_start();
//after calling session_start(), assign anything to $_SESSION
$_SESSION['foo']='bar';
//now let's generate HTML
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>Multidome- The UK's favorite telescopic pool enclosure.</TITLE>
<?
//you can use $_SESSION also after sending text to the browser
$_SESSION['foo2']='kkk';
?>

If it didn't solve your problem, turn on debugging (including E_NOTICE
reporting) - it's the best way to find some bugs in code.

--
Wiktor Walc
http://phpfreelancer.net
Apr 10 '07 #5
On Apr 10, 6:44 am, iktorn <s...@phpfreelancer.netwrote:
dangerd napisał(a):
On Apr 9, 8:52 pm, iktorn <s...@phpfreelancer.netwrote:
dangerd napisał(a):
Hello,
I got rid of the session_register() and the problem persists. I think
what is happening is that the $_SESSION[$authdata] (I took your
advise on board) dissapears after five or so refreshes but then
reappears after another refresh. There does not seem to be a pattern
on the number of refreshes it takes for $authdata to dissapear.
Strange...
Duncs

There is always some reasonable solution for such problems ;)

Inhttp://www.multidome.co.uk/test/gallery.txtauthorisation.php
is included afer DOCTYPE declaration, therefore session_start()
isn't called at the beginning of the script and your session is being
lost (if you don't have some output buffering turned on).

The proper way of using session is:

<?
//must be called on every page
session_start();
//after calling session_start(), assign anything to $_SESSION
$_SESSION['foo']='bar';
//now let's generate HTML
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>Multidome- The UK's favorite telescopic pool enclosure.</TITLE>
<?
//you can use $_SESSION also after sending text to the browser
$_SESSION['foo2']='kkk';
?>

If it didn't solve your problem, turn on debugging (including E_NOTICE
reporting) - it's the best way to find some bugs in code.

--
Wiktor Walchttp://phpfreelancer.net
Wiktor,

I have tried what you suggested but the problem, still persists. I
have updated the txt code so you can see for yourself.
....any more ideas?

Thanks

Duncs

Apr 10 '07 #6
dangerd napisał(a):
On Apr 10, 6:44 am, iktorn <s...@phpfreelancer.netwrote:
>dangerd napisał(a):
Wiktor,

I have tried what you suggested but the problem, still persists. I
have updated the txt code so you can see for yourself.
...any more ideas?

Thanks

Duncs
replace auth function with these piece of code, should work

function auth ( $login = '', $password = '' )
{
if (isset($_SESSION['authdata']['login'])) {
return TRUE;
}
elseif (!empty($login))
{
if ( $login == myuser && $password == mypass or $login ==
myuser2 && $password == mypass2 ) {
$_SESSION['authdata'] = array ( "login" =$login );
return TRUE;
}

$_SESSION['authdata'] = array();
return FALSE;
}
else {
return FALSE;
}
}

your previous function used "global $authdata;" - variable $authdata
would only exist if you had register_globals turned on.
--
Wiktor Walc
http://phpfreelancer.net
Apr 10 '07 #7
On Apr 10, 7:53 am, iktorn <s...@phpfreelancer.netwrote:
dangerd napisał(a):
On Apr 10, 6:44 am, iktorn <s...@phpfreelancer.netwrote:
dangerd napisał(a):
Wiktor,
I have tried what you suggested but the problem, still persists. I
have updated the txt code so you can see for yourself.
...any more ideas?
Thanks
Duncs

replace auth function with these piece of code, should work

function auth ( $login = '', $password = '' )
{
if (isset($_SESSION['authdata']['login'])) {
return TRUE;
}
elseif (!empty($login))
{
if ( $login == myuser && $password == mypass or $login ==
myuser2 && $password == mypass2 ) {
$_SESSION['authdata'] = array ( "login" =$login );
return TRUE;
}

$_SESSION['authdata'] = array();
return FALSE;
}
else {
return FALSE;
}

}

your previous function used "global $authdata;" - variable $authdata
would only exist if you had register_globals turned on.

--
Wiktor Walchttp://phpfreelancer.net
Ace!!

You nailed it. You have made my day!

You are a king amongst men my friend.

Thanks

Apr 12 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Lina Manjarres | last post: by
31 posts views Thread by Harry Simpson | last post: by
10 posts views Thread by tshad | last post: by
3 posts views Thread by Alan Wang | last post: by
3 posts views Thread by Phillip N Rounds | last post: by
26 posts views Thread by BillE | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.