SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code:
    <?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.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

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

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi multichild,

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

    http://stackoverflow.com/questions/1...after-redirect

    Do you have a dev environment?

  4. #4
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would look into making a script that uses a cookie to see if the user is still logged in.

  7. #7
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,386
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi multichild,

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

  8. #8
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    Code:
    <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.

  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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/

  10. #10
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,386
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Franny_uk View Post
    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.
    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?

  11. #11
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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)

  12. #12
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  13. #13
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •