Jump to content

Archived

This topic is now archived and is closed to further replies.

dual_alliance

Sessions not working (again!)

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...)

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites
FireFox and Internet Explorer will generate different sessions server side I think...

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
I always use meta tags to refresh pages that I write that handle processing post variables... And the meta tags work fine in FF and IE for me...

Share this post


Link to post
Share on other sites
Well the first page that l login in on IE it shows the session arrary, l refresh the page again works fine.  Click a link and the session dies...

Share this post


Link to post
Share on other sites
Try it, I dont know cos I always use FF, and check with IE, with the setting to refresh on every page

you could put some meta tags up, which stop caching, meaning IE would have no choice but reload the page on every visit

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Hello

<meta http-equiv="Pragma" content="no-cache;>

You not ending this properly
<meta http-equiv="Pragma" content="no-cache"> (end with " not ;)
This could create problems

Share this post


Link to post
Share on other sites

×

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.