Jump to content

Recommended Posts

Hey

 

I am having quite a strange error with sessioning. I am using my University webspace to host a website and simply want to be able to utilise an admin login system so that I am able to edit certain sections of the web site, similar format to Wiki!

 

However, the session variables are initialised ok on successful login, and then all subsequent pages use a header include, which checks for the existance of the session variable and sets an admin status (true or null) The rest of the code then checks this variable to see whether the edit links are shown for certain areas, and also makes sure that if the direct link is typed in, the headerfile contains the admin variable, other wise it denys access.

 

The problem is that pages do not always recognise the session. To clarify I can log in, go to a page, not see the edit buttons, press refresh and they appear, refresh a couple more times and they disappear, refresh again and they may come back etc etc etc. It is a very intermittent problem with regard to when they appear or do not.

 

I decided to write a simple test file to see if this still occured with the following code:

 

<?php session_start();

 

if ($_SESSION['user']){ //if the session variable set on login (ignoring the aforementioned header file)

 

echo "hello";

 

}else{

 

echo "goodbye";

 

}

 

?>

 

on testing this program by loging in accessing this page and then pressing refresh numerous times, I recieved the following outputs:

 

goodbye

hello

hello

hello

goodbye

hello

hello

goodbye

goodbye

hello

goodbye

 

as you can see it tends to be rather random.

 

This is proving to be quite a problem as it is denying me access to certain pages which I should be able to reach at times.

 

I do not think that this is related to a session expiration, due to the fact that after a negative result has been received, apositive may follow, indicating that the session, and its variable are active.

 

I really really need help with this guys, its driving me insane, and the launch date of the website into the public domain is pretty soon!

 

Many many thanks in advance

 

(sorry for the long post!)

 

Adam.

Link to comment
https://forums.phpfreaks.com/topic/41607-strange-session-error/
Share on other sites

thanks for the reply, still same thing is happening I'm afraid :(

 

Could it be something related to the way in which I am initialising the variable I simply use

 

session_start() (at the beginning of the page)

 

then $_SESSION['user'] = "admin"; where it is required ?

Link to comment
https://forums.phpfreaks.com/topic/41607-strange-session-error/#findComment-201587
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.