Forum Moderators: coopster

Message Too Old, No Replies

Session time expired problem

         

mukhtar2t

8:15 am on Oct 17, 2005 (gmt 0)

10+ Year Member



Peace be upon you
I have a probem when my code excute this pice of code :

switch(@$id)
{
case 1 :
if (@$_SESSION[level'] == 'ok')
{
do_header();
include_once("../../myrep/reports.php");
do_footer();
}
else
{
header("location:?id=2");
}
break;
case 2 :
echo "You are not authorized.";
break;
...

Althow the session variabel is ok but the browser show the included page for one or tow seconds and after that logs out with message "Session time is expired".

Are there any one know solution for this problem.

Thank you

jatar_k

3:25 pm on Oct 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld mukhtar2t,

I am not quite understanding the scenario

>> show the included page for one or tow seconds and after that logs out

do you mean it logs out on the next click?
or is there some type of refresh on the page?
are do you mean if they reload that same page?

are you using session_start at the top of every page?

ergophobe

4:49 pm on Oct 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



followup question that may be relevant or not, depending... Are you using the default session handler on a shared host?

Also, is the behavior 100% consistent (always logs out after two seconds?). After one second? Sometimes not until five minutes?

mukhtar2t

7:27 am on Oct 18, 2005 (gmt 0)

10+ Year Member



thank you all.

first it seems to be some type of refresh as you said Mr. jatar_k and also i am using session_start at the top of every page.

Mr. ergophobe i am not understand your question about default handler but it is allways log out after fixed period of about few seconds i think tow.

and i had notice that in my localhost windows PC the code work properly but in my linux server it dosnt.

best regards
and sorry if my english is not good.

jatar_k

3:31 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> sorry if my english is not good

no need to apologize for things like that

hmmm, can you maybe see if the session is actually getting set properly?

this is your test

if (@$_SESSION[level'] == 'ok')

remove the @ from there and maybe try echo'ing that value on each page to make sure it is being set

echo '<p>level: ',$_SESSION[level'];
if ($_SESSION[level'] == 'ok')

then see if the value is correct

mukhtar2t

6:55 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



i checked session and its ok but i try to make the include page in the same folder and the problem was not occured i dont know why.

but i think there is a solution to this problem with out making all file in one folder.

jatar_k

7:12 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if the session value is ok then you must be getting to the right part of your if statement

maybe it is just an include problem

you could try absolute paths instead of ../../

where is your include file from the web root?

so from the / of your website

ergophobe

7:56 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Muhktar,

Given your answers, my question wasn't relevant, so you can forget about it for now anyway.

In the same light as Jatar_K's session test, check also that $id is getting set.

Also, get rid of the @ in this statement

switch(@$id)

Perhaps the include problem is because $id is getting unset? PHP would treat this as $id = 0, which would fail both of your switch criteria.

Try putting this at the top of your script, but after the session_start() command:

if (!isset($id)) {
echo '$id is undefined';
}

if (!isset($_SESSION))
{
echo 'session is not set';
}

This will at least let you know what's going on.

mukhtar2t

6:50 am on Oct 19, 2005 (gmt 0)

10+ Year Member



The Peace be upon you guys.

>> you could try absolute paths instead of ../../
>> so from the / of your website

i was tried both methods first one by my website it produce errors like this :


Warning: main(): URL file-access is disabled in the server configuration ...

Warning: ... mainfailed to open stream: no suitable wrapper could be found ...

Warning: main(): Failed opening ...for inclusion (include_path='.:/usr/share/pear')

and second by the absolute / path and its work but same problem was occured.

the point what i want to refer that i had using relative path like ../../ a lot of times in my code and my include pages work properly and this code with same file names work properly in my localhost.

ergophobe.
>> Perhaps the include problem is because $id is getting unset? PHP would treat this as $id = 0, which would fail both of your switch criteria.

i have already check to $id at the top of my code like this :


if ((@$_SESSION['User_Level']!= '3') ¦¦ empty($id))
{
Logout("../myrep/");
exit();
}

so that the $id and $_SESSION are tested.

I think that php include another page that contains validation to level rather than 3 and logout immediatly when it make a validation.

mukhtar2t

7:53 am on Oct 19, 2005 (gmt 0)

10+ Year Member



Ok guys thank you very much.

i fount the problem you are right it was in session variable it was not ok set to allowble value.

thank you again Mr. Jatar_k and Mr. ergophobe

ergophobe

5:46 pm on Oct 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm glad you got that sorted... didn't notice your post before my little hiatus.