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

Join 136,582 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,931 people online right now. Registration is fast and FREE... Join Now!




Sessions Changing

 
Reply to this topicStart new topic

Sessions Changing, Causes logout.

UmmmmIdk
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
+Quote Post

BetaWar
RE: Sessions Changing
7 Oct, 2008 - 03:11 PM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,026



Thanked: 82 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
+Quote Post

UmmmmIdk
RE: Sessions Changing
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
+Quote Post

JBrace1990
RE: Sessions Changing
7 Oct, 2008 - 04:43 PM
Post #4

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 476



Thanked: 22 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
+Quote Post

engale
RE: Sessions Changing
7 Oct, 2008 - 08:17 PM
Post #5

D.I.C Addict
Group Icon

Joined: 30 Sep, 2008
Posts: 549



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
+Quote Post

akozlik
RE: Sessions Changing
8 Oct, 2008 - 07:56 AM
Post #6

D.I.C Addict
Group Icon

Joined: 25 Feb, 2008
Posts: 614



Thanked: 24 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
+Quote Post

CTphpnwb
RE: Sessions Changing
8 Oct, 2008 - 09:45 AM
Post #7

D.I.C Regular
***

Joined: 8 Aug, 2008
Posts: 383



Thanked: 23 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
+Quote Post

akozlik
RE: Sessions Changing
8 Oct, 2008 - 11:22 AM
Post #8

D.I.C Addict
Group Icon

Joined: 25 Feb, 2008
Posts: 614



Thanked: 24 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
+Quote Post

CTphpnwb
RE: Sessions Changing
8 Oct, 2008 - 11:41 AM
Post #9

D.I.C Regular
***

Joined: 8 Aug, 2008
Posts: 383



Thanked: 23 times
My Contributions
In that case, what's in allowadmin.php?


User is offlineProfile CardPM
+Quote Post

UmmmmIdk
RE: Sessions Changing
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
+Quote Post

CTphpnwb
RE: Sessions Changing
8 Oct, 2008 - 04:41 PM
Post #11

D.I.C Regular
***

Joined: 8 Aug, 2008
Posts: 383



Thanked: 23 times
My Contributions
Could this be a browser issue? Does it happen with FF, Safari, Camino, Opera, etc.?
User is offlineProfile CardPM
+Quote Post

UmmmmIdk
RE: Sessions Changing
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
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:39AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month