Jump to content


Photo

Sessions not working (again!)


  • Please log in to reply
13 replies to this topic

#1 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 08 August 2006 - 10:22 PM

Well if you were one of the people that helped me with my previous thread (which l thankyou so much for helping me) http://www.phpfreaks...c,103269.0.html 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...)

#2 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 08 August 2006 - 10:34 PM


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

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

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

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



#3 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 10:44 PM

FireFox and Internet Explorer will generate different sessions server side I think...
Why doesn't anyone ever say hi, hey, or whad up world?

#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 08 August 2006 - 10:50 PM

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
Tell me the problem, I will try tell you the solution

#5 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 08 August 2006 - 10:58 PM


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

I like to use:

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

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

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



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

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

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.

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


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
Array ( )
so the session must be getting killed once l click on to a next page.  Why though?

#6 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 11:02 PM

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...
Why doesn't anyone ever say hi, hey, or whad up world?

#7 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 08 August 2006 - 11:05 PM

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

#8 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 08 August 2006 - 11:07 PM

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
Tell me the problem, I will try tell you the solution

#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 08 August 2006 - 11:10 PM

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

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

Legend has it that reading the manual never killed anyone.
My site

#10 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 08 August 2006 - 11:18 PM

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:

header("Cache-control: private");

That will force the page to reload, instead of using the cached version.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#11 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 08 August 2006 - 11:20 PM

I have that on every page.....


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

<?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');

No luck :(, l have also tried removing:

header("Cache-control: private");

No luck their either...


I'm going to sleep since its 12:30am here.  I'll worry about this in the morning

#12 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 09 August 2006 - 07:59 AM

Any ideas?

#13 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 09 August 2006 - 10:38 AM

bump

#14 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 09 August 2006 - 11:14 AM

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
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users