473,498 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1563
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2359
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
6
656
by: Lina Manjarres | last post by:
Hello, I have a session variable in a login page. Then I go to a form page where I uses the ProfileID and the UserID. Then I go to a result page where I would like to use the UserID as a filter,...
4
5573
by: PJ | last post by:
A particular page seems to be having issues with correctly setting Session variables. I am setting a couple of session variables on the Page_Unload event. While stepping through code, the...
31
6966
by: Harry Simpson | last post by:
I've come from the old ASP camp where session variables were not used. When i started using ASP.NET in 2001, I started using them again because it was ok from what I'd read. I've been merrily...
10
3477
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
3
2888
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
3
2663
by: Phillip N Rounds | last post by:
I'm writing a user control which has two states: Active & InActive. I additionally am required that there to be only one active control per page, and all logic has to be contained within the...
18
3396
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
26
3576
by: BillE | last post by:
Some ASP.NET applications use Session Variables extensively to maintain state. These should be re-written to use viewstate, hidden fields, querystring, etc. instead. This is because if a user...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.