Jump to content

Sessions not working (again!)


dual_alliance

Recommended Posts

Well if you were one of the people that helped me with my previous thread (which l thankyou so much for helping me) [url=http://www.phpfreaks.com/forums/index.php/topic,103269.0.html]http://www.phpfreaks.com/forums/index.php/topic,103269.0.html[/url] you will know that l solved the problem.  Well so l thought since l only use firefox l didn't think about IE until just then l thought l would test it and see what happens and it tells me to login again! (Before commenting you should read my previous thread to reduce duplicate ideas)

Thankyou for your help it is greatly appreciated,

dual_alliance

(Note: I have IE to allow all cookies but l'm using sessions so l don't see the problem.  Also l thought it could of been my IE so l asked a friend to test it in IE and she got the same problem...)
Link to comment
Share on other sites


Is it not seeing the session at all or is the session variables empty?

I like to use:
[code]
<?php
if(isset($_SESSION['username'])) {
  echo "You're username is: {$_SESSION['username']}\n";
} else {
  echo "You are not logged in";
}
?>
[/code]

You could also try outputting the $_SESSION:
[code]
<?php
print_f($_SESSION);
?>
[/code]

That way it will show you what is set for the session :)

Link to comment
Share on other sites

Here is something about IE
IE does not refresh the page on every visit, it is a pain
Either press CTRL + F5, to refresh and reload the data
OR
to stop this all the time in IE
click
Tools -> Internet Options ->
Settings (located middle right)

4 Radio buttons will appear, Default is Automaticly
Best working should be Every visit to the page (top one)

I am going by memory here, cos I cant be bothered to open IE, so excuse minor mistakes
Link to comment
Share on other sites

[quote author=SharkBait link=topic=103493.msg412081#msg412081 date=1155076490]

Is it not seeing the session at all or is the session variables empty?

I like to use:
[code]
<?php
if(isset($_SESSION['username'])) {
  echo "You're username is: {$_SESSION['username']}\n";
} else {
  echo "You are not logged in";
}
?>
[/code]

You could also try outputting the $_SESSION:
[code]
<?php
print_f($_SESSION);
?>
[/code]

That way it will show you what is set for the session :)


[/quote]

Yea kingarthur (sorry if spelt incorrectly) advised me to do that, and l have it on every page

[code]Array ( [userid] => 8 [username] => dual_alliance [password] => 0926274431b9d947d6b903f61c***** )[/code]

And it transfers to the next page when l am using firefox...  Also when l log in with IE on the first page it shows that also however when l click any link it asks me to login again.

[quote author=onlyican link=topic=103493.msg412097#msg412097 date=1155077453]
Here is something about IE
IE does not refresh the page on every visit, it is a pain
Either press CTRL + F5, to refresh and reload the data
OR
to stop this all the time in IE
click
Tools -> Internet Options ->
Settings (located middle right)

4 Radio buttons will appear, Default is Automaticly
Best working should be Every visit to the page (top one)

I am going by memory here, cos I cant be bothered to open IE, so excuse minor mistakes
[/quote]

Well l could always write a tutorial for people who will be logging in and having a problem... but shorley this cant be the problem.


When l use print_f($_SESSION) before exit() on the next page in IE it shows [code]Array ( )[/code] so the session must be getting killed once l click on to a next page.  Why though?
Link to comment
Share on other sites

If you want to use sessions, you need session_start() first - on any page where you want to use sessions.

[code]<?php
session_start();
if(isset($_SESSION['username'])) {
  echo "You're username is: {$_SESSION['username']}\n";
} else {
  echo "You are not logged in";
}
?>[/code]
Link to comment
Share on other sites

Since it works in FF and not IE, I'm assuming you initiate the session properly, but in that case it's probably the cache.  You can adjust this with headers (because as someone mentioned, IE likes to cache pages... good for bandwidth, bad for you).  Try adding this to your header:

[code]header("Cache-control: private");[/code]

That will force the page to reload, instead of using the cached version.
Link to comment
Share on other sites

I have that on every page.....


I modified my code around hoping that this might work, also using the META tag idea.

[code=php:0]<?php

session_start();
header("Cache-control: private");

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Pragma" content="no-cache;>
</head>
<body>

<?php

// Is the user logged in?

if (!isset($_SESSION['username'])) {
    echo "You aren't logged in.";
    include("index.php");
    exit();
}else{
include('db.php');[/code]

No luck :(, l have also tried removing:

[code=php:0]header("Cache-control: private");[/code]

No luck their either...


I'm going to sleep since its 12:30am here.  I'll worry about this in the morning
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.