Take the 2-minute tour ×

I am working on E-commerce Web Application, which is having users and permissions to them.. So according to their permission,

For Ex: I am storing variable $chk = 'write' or $chk = 'read' on session and my condition is

if ($chk == 'write')
   // some function here to modify the page & its content
   // If true, then display SAVE button to save all changes made.

But, Sometimes my page cant access this variable, the value of $chk is unknown hence its not displaying SAVE button. But, it shows the button after refreshing the page or visiting sometime later. Can anyone help me to solve this.. Thanks in advance

share|improve this question

migrated from programmers.stackexchange.com Oct 1 '12 at 14:17


This seems more appropriate for Stack Overflow as this is not a design problem but a code error. But, chances are this Q would get closed there too, need more code that is surrounding your condition. Chances are you aren't calling session_start() appropriately. –  cspray Oct 1 '12 at 13:49
how are you storing them in the session? how are you pulling them out of the session? As cspray says need more code. Also are we talking single server? multiple servers behind Load Balancer. Sessions stored on server , or in database? –  Doon Oct 1 '12 at 14:19
Please add relevant code. The block shown gives no insight e.g. how do you assign current value to '$chk' ? –  Alfabravo Oct 1 '12 at 14:20

1 Answer 1

up vote 1 down vote accepted

Session variables in PHP need to be stored in the $_SESSION magic variable to persist them across multiple pages. To ensure that a page has access to the session, you also need to call session_start() on each page.

In this case, changing $chk to $_SESSION['chk'] and adding session_start() at the top of each page will probably do the trick.

share|improve this answer
this is working.. thanks –  Anusha Oct 3 '12 at 4:21

Your Answer


