User logged out of admin when page refrehses to reveal new report added

I have an admin area only accssible by managers, and this area shows the reports that are being added by the workers on health and safety issues.

The problem Ive got is that the manager logs into the admin area and I have the page refreshing every 50 seconds, but if a report is added when the refresh occurs it logs him out.

Is this a usual thing, or can this be sorted out.

I’m guessing its the script that is checking ot make sure they have logged in before being allowed to use enter the page, which is this:


<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
header("location: index.php");
exit();}
?>

Or is it likely to be something else as the sessions seem to be working fine and it doesnt log them out otherwise.

Just happens when they are currently logged in the page refreshes and a worker as added a new report, and so on the page refreshing the report becomes available to the manager.

OK I isolated the problem to the authentication code above by commenting it out and when the refresh came the new report showed and the user was kept logged in, which it would do obviously as there no checking there now, but cant understand what its changing to make it log out, when all that is happening is the page is refreshing and new data exists in the database.

This is the re-load script im using:


<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}
//   -->
</script>

Hi multichild,

Stack overflow suggests that it might be an issue with your host:

http://stackoverflow.com/questions/17242346/php-session-lost-after-redirect

Do you have a dev environment?

Hi Franny_uk,

Ah right, thats a right old shame isnt it if it is…

I think the hosting is with Fasthosts so will check it out first.

Like you say might be worth alos checking it in a dev environment too.

Thanks for getting back to me though, always much appreciated.

Contacted the hosting company who where no help at all, just saying that scripting problems are my problem and not theirs, so with that, I’m going to have to think about using a new user authentication script.

Can someone explain what is happening with this issue, as in is it that the sessions are being cleaned, or is there some other possible problem.

I went through the checklist from stackoverflow and nothing changed, damn shame this is, as these little issues hold everything else up.

I would look into making a script that uses a cookie to see if the user is still logged in.

Hi multichild,

Could you share the html for the form that’s being submitted?

Hi Fretburner,

It isnt a form thats being submitted as such, its a a page that has sections with each section containing reports from the database, all is fine and the refresh is fine until someone on another computer fills in the form and the report is submitted, then when the page refreshes the and the new report adds to the list the user is logged out.

This is the bit that deals with the new reports coming in:


<div id="unread-Reports">
<? $a=mysql_query("select count(UniqueIdentifier) as total1 from hazzard where HazardorNearMiss=''");
$data=mysql_fetch_assoc($a);
//echo $data['total1'];
?>
<p><strong>New Reports Not Completed By Manager: <span style="font-size:14px; font-weight:normal; vertical-align:2px; color:#71A6D4">[<? echo $data['total1'] ?>]</span> - <span style="font-size:12px">(Managers Input / Delete)</span></strong></p>
</div>
<div id="unread-Reports-Data">
<table width="1000">
<?
$a=mysql_query("select UniqueIdentifier, Name, Employerofperson, Location, DateOccured, HazardorNearMiss from hazzard WHERE HazardorNearMiss='' ORDER by UniqueIdentifier DESC");
while($x=mysql_fetch_assoc($a)){
?>
<? if ($count_line=="") { ?>
<tr style="background-color:#333366; color:#FFFFFF;">
<td width="70" align="center"><a href="detail.php?ID=<?=$x['UniqueIdentifier']?>" title="Click for more details" style="font-size:11px">View Details</a></td> <td><span class="padding_Detail"><?=$x['Name']?></span></td><td><span class="padding_Detail"><?=$x['Employerofperson']?></span></td><td><span class="padding_Detail"><?=$x['Location']?></span></td><td><span class="padding_Detail"><? print( date( 'd-m-Y H:i', strtotime( $x['DateOccured'] ) ) );?></span></td>
</tr>
<? $count_line="2"; ?>
<? } else { ?>
<tr style="background-color:#8CB7DC; color:#FFFFFF;">
<td width="70" align="center"><a href="detail.php?ID=<?=$x['UniqueIdentifier']?>" title="Click for more details" style="font-size:11px">View Details</a></td> <td><span class="padding_Detail"><?=$x['Name']?></span></td><td><span class="padding_Detail"><?=$x['Employerofperson']?></span></td><td><span class="padding_Detail"><?=$x['Location']?></span></td><td><span class="padding_Detail"><? print( date( 'd-m-Y H:i', strtotime( $x['DateOccured'] ) ) );?></span></td>
</tr>
<? $count_line=""; ?>
<? } ?>
<? } ?>
</table>
</div>

Pretty basic really, but the page as a whole is quite a lot, so maybe if you want access to it or I can break it up into chunks and put it in a reply post.

Thanks for coming back though, as im not getting anywhere with it.

Hi multichild,

I’ve been wracking my brains over this, and I can’t see why you’re users are getting logged out. However I’ve had another thought. Rather than refreshing the page could you use a jQuery AJAX call to a php script to load the H&S reports? You can return HTML via jQuery.get, so you could use a seperate php file to construct your table, then use jQuery to add it to your managers page. You could set this function to run on a timed basis as well, so you shouldn’t get the problem with the users being logged out.

Just a thought.

http://api.jquery.com/jQuery.get/

I was going to suggest something similar myself, although I don’t think it will solve the logout problem, as an ajax request is essentially the same as a normal browser request. I think the problem must be something to do with sessions, although it’s difficult to imagine what the problem could be as logins from separate browsers will get separate sessions.

Multichild, is this problem actually occurring in practice on separate machines, or this is a situation you’re testing on your development machine?

Yes this is it, the person adding the report is on a different computer somewhere in the UK. The manager in his office wants to be able to keep that admin page open and through the day the reports become available to him, and he wanted the refresh so that he could see them.

What I will do is ask another person to check if for me and see what happens.

I’ll be back! (Arnie style)

Right it must be a problem I have my end, as just checked with someone else to create the report and a couple of other random people to log into the admin and check if they get logged out and suprisingly they didnt, so all my stress and wasting your time could have been averted by doing this, so sorry for that.

So thats that sorted.

Thanks

Ahh well. Glad it’s not a problem.

If it ever comes up for your users you could always say it’s an added security feature.