Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 131,567 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,166 people online right now. Registration is fast and FREE... Join Now!




Sessions Changing

 
Reply to this topicStart new topic

Sessions Changing, Causes logout.

UmmmmIdk
post 7 Oct, 2008 - 03:03 PM
Post #1


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10


My Contributions


I have my index page and then a separate directory for the admin panel. Whenever I go from admin panel to the index, the first time I open the browser, the session changes and logs the user out. If I log back in, the session stays when I repeat the same task. I setup a session header that displays the sessions at the top of the page and the session changes when this error occurs.

Here is some coding that will hopefully assist:

TOP OF ADMIN.PHP

CODE

<?php
include('sessions.php');
include('allowadmin.php');
include('header.php'); ?>


HEADER.PHP IN ADMIN DIRECTORY

CODE

<div id='navbar' align='middle'>
    <ul>
        Logged in as <?= $_SESSION['user_name'];?>
        &nbsp;&nbsp;&nbsp;<a href="http://www.mysite.com/">Home</a>
        &nbsp;&nbsp;<a href="admin.php">Admin</a>
    </ul>
</div>


SESSIONS.PHP
CODE

<?php
session_start();
echo session_id();
?>


The sessions.php is included in all pages on the site so the session_start() is included on all pages.

This post has been edited by UmmmmIdk: 7 Oct, 2008 - 03:04 PM
User is offlineProfile CardPM

Go to the top of the page


BetaWar
post 7 Oct, 2008 - 03:11 PM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,976



Thanked 77 times

Dream Kudos: 1175
My Contributions


Are you talking about closing the browser and then opening it again? If that is the case it is because sessions only stay active as long as you set them to in the code and only that as long as the browser window is open. When you close the window the session is deleted.

Hope that helps, but there is a chance that I mis-understood what your problem was.
User is offlineProfile CardPM

Go to the top of the page

UmmmmIdk
post 7 Oct, 2008 - 03:16 PM
Post #3


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10


My Contributions


QUOTE(BetaWar @ 7 Oct, 2008 - 04:11 PM) *

Are you talking about closing the browser and then opening it again? If that is the case it is because sessions only stay active as long as you set them to in the code and only that as long as the browser window is open. When you close the window the session is deleted.

Hope that helps, but there is a chance that I mis-understood what your problem was.


Thanks, but yes you misunderstood, I know that lol tongue.gif When I first open the browser and login and navigate from any page to the admin panel and then go back to the index.php page, the session changes. When I relogin without closing the browser, this problem doesn't occur.
User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 7 Oct, 2008 - 04:43 PM
Post #4


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 474



Thanked 21 times

Dream Kudos: 350
My Contributions


Well, it appears Akozlik isn't the only one with this problem. We've yet to come up with a fix, but we'll be sure to let you know if we figure it out.
User is offlineProfile CardPM

Go to the top of the page

engale
post 7 Oct, 2008 - 08:17 PM
Post #5


D.I.C Addict

Group Icon
Joined: 30 Sep, 2008
Posts: 532



Thanked 2 times

Dream Kudos: 50
My Contributions


Here is a link to another post on the board with the same problem it has some things you can check out.

PHP Sessions changeing.

Hope some of that might work for you.
User is offlineProfile CardPM

Go to the top of the page

akozlik
post 8 Oct, 2008 - 07:56 AM
Post #6


D.I.C Addict

Group Icon
Joined: 25 Feb, 2008
Posts: 586



Thanked 22 times

Dream Kudos: 750
My Contributions


If you figure it out post it here, or PM me. My brains absolutely fried trying to come up with a fix.

You my want to try using the session_regenerate_id() function and see if it helps.

Session Regenerate Id
User is offlineProfile CardPM

Go to the top of the page

CTphpnwb
post 8 Oct, 2008 - 09:45 AM
Post #7


D.I.C Regular

***
Joined: 8 Aug, 2008
Posts: 330



Thanked 19 times
My Contributions


Shouldn't this line:
CODE
        Logged in as <?= $_SESSION['user_name'];?>

be this?
CODE
        Logged in as <?php echo $_SESSION['user_name'];?>

User is offlineProfile CardPM

Go to the top of the page

akozlik
post 8 Oct, 2008 - 11:22 AM
Post #8


D.I.C Addict

Group Icon
Joined: 25 Feb, 2008
Posts: 586



Thanked 22 times

Dream Kudos: 750
My Contributions


Actually

php

<?= $whatever; ?>


Is short hand for

php

<?php echo $whatever; ?>


Short tags need to be enabled on the server though
User is offlineProfile CardPM

Go to the top of the page

CTphpnwb
post 8 Oct, 2008 - 11:41 AM
Post #9


D.I.C Regular

***
Joined: 8 Aug, 2008
Posts: 330



Thanked 19 times
My Contributions


In that case, what's in allowadmin.php?

User is offlineProfile CardPM

Go to the top of the page

UmmmmIdk
post 8 Oct, 2008 - 12:26 PM
Post #10


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10


My Contributions


QUOTE(CTphpnwb @ 8 Oct, 2008 - 12:41 PM) *

In that case, what's in allowadmin.php?


allowadmin.php is just checking to make sure the sessions are set and the page can be viewed, AKA checkLogin kinda.

here are the contents, not much so I'll post it all.

CODE

<?php

$perms = $_SESSION['user_perms'];
if(isset($_SESSION['logged_in']) && $perms === 'A')
{
}
else{
    header('location:http://www.mysite.com/index.php');
}
?>
User is offlineProfile CardPM

Go to the top of the page

CTphpnwb
post 8 Oct, 2008 - 04:41 PM
Post #11


D.I.C Regular

***
Joined: 8 Aug, 2008
Posts: 330



Thanked 19 times
My Contributions


Could this be a browser issue? Does it happen with FF, Safari, Camino, Opera, etc.?
User is offlineProfile CardPM

Go to the top of the page

UmmmmIdk
post 8 Oct, 2008 - 06:52 PM
Post #12


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 10


My Contributions


QUOTE(CTphpnwb @ 8 Oct, 2008 - 05:41 PM) *

Could this be a browser issue? Does it happen with FF, Safari, Camino, Opera, etc.?


That is what I was thinking. It only happens in Firefox and Google Chrome. It works fine in all others I have tried.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 03:09AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month