Connecting Tech Pros Worldwide Forums | Help | Site Map

DIssapearing/reappearing Session variables

dangerd
Guest
 
Posts: n/a
#1: Apr 9 '07
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


iktorn
Guest
 
Posts: n/a
#2: Apr 9 '07

re: DIssapearing/reappearing Session variables


dangerd napisał(a):
Quote:
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
dangerd
Guest
 
Posts: n/a
#3: Apr 9 '07

re: DIssapearing/reappearing Session variables


On Apr 9, 8:52 pm, iktorn <s...@phpfreelancer.netwrote:
Quote:
dangerd napisał(a):
>
Quote:
Hello,
>
Quote:
Thought I'd try this forum as I got some useful help from here before.
>
Quote:
Duncs
>
Quote:
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,
Quote:
>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

dangerd
Guest
 
Posts: n/a
#4: Apr 9 '07

re: DIssapearing/reappearing Session variables


On Apr 9, 8:52 pm, iktorn <s...@phpfreelancer.netwrote:
Quote:
dangerd napisał(a):
>
Quote:
Hello,
>
Quote:
Thought I'd try this forum as I got some useful help from here before.
>
Quote:
Duncs
>
Quote:
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

iktorn
Guest
 
Posts: n/a
#5: Apr 10 '07

re: DIssapearing/reappearing Session variables


dangerd napisał(a):
Quote:
On Apr 9, 8:52 pm, iktorn <s...@phpfreelancer.netwrote:
Quote:
>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
dangerd
Guest
 
Posts: n/a
#6: Apr 10 '07

re: DIssapearing/reappearing Session variables


On Apr 10, 6:44 am, iktorn <s...@phpfreelancer.netwrote:
Quote:
dangerd napisał(a):
>
Quote:
On Apr 9, 8:52 pm, iktorn <s...@phpfreelancer.netwrote:
Quote:
dangerd napisał(a):
>
Quote:
Hello,
>
Quote:
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...
>
Quote:
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

iktorn
Guest
 
Posts: n/a
#7: Apr 10 '07

re: DIssapearing/reappearing Session variables


dangerd napisał(a):
Quote:
On Apr 10, 6:44 am, iktorn <s...@phpfreelancer.netwrote:
Quote:
>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
dangerd
Guest
 
Posts: n/a
#8: Apr 12 '07

re: DIssapearing/reappearing Session variables


On Apr 10, 7:53 am, iktorn <s...@phpfreelancer.netwrote:
Quote:
dangerd napisał(a):
>
Quote:
On Apr 10, 6:44 am, iktorn <s...@phpfreelancer.netwrote:
Quote:
dangerd napisał(a):
>
Quote:
Wiktor,
>
Quote:
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?
>
Quote:
Thanks
>
Quote:
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

Closed Thread