Session is not available in different browser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deecee2000
Forum Newbie
Posts: 1
Joined: Tue Jun 16, 2009 3:36 pm

Session is not available in different browser

Post by deecee2000 »

My code:

File1.php
<?php
session_start();
$_SESSION['name'] = 'ABC';
?>

File2.php
<?php
session_start();
if(isset($_SESSION['name'])
{
echo "Session Set";
}
else
{
echo "Session not Set";
}
?>

When I try to run first file "file1.php" and then "file2.php" in Firefox, session value showing correctly at file2.php
But then if I try "file2.php" in IE the session value is not showing there.

How can I fix this issue.

Any help would appreciated.
Thanks in Advance.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Session is not available in different browser

Post by requinix »

You can't copy session values across browsers like that.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Session is not available in different browser

Post by jackpf »

The session id is stored in a cookie. Browsers use their own cookie management.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Session is not available in different browser

Post by John Cartwright »

tasairis wrote:You can't copy session values across browsers like that.
You most certainly can. A quick google for "session hijacking" will prove this wrong.

However, I think the OP misspoke a little. Perhaps he meant to say after repeating the process that worked in FF, the same did not work in IE.

..but as jackpf hinted, do you have cookies enabled in IE?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Session is not available in different browser

Post by requinix »

John Cartwright wrote:
tasairis wrote:You can't copy session values across browsers like that.
You most certainly can. A quick google for "session hijacking" will prove this wrong.
I was careful: note the inclusion of "like that" ;)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Session is not available in different browser

Post by John Cartwright »

tasairis wrote:
John Cartwright wrote:
tasairis wrote:You can't copy session values across browsers like that.
You most certainly can. A quick google for "session hijacking" will prove this wrong.
I was careful: note the inclusion of "like that" ;)
Touché
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Session is not available in different browser

Post by jackpf »

What you could do, is if the user is using the same IP address, give them all the session data for that IP address. Although...this would be a major security risk 8O

But I guess it is possible.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Session is not available in different browser

Post by requinix »

jackpf wrote:What you could do, is if the user is using the same IP address, give them all the session data for that IP address. Although...this would be a major security risk 8O

But I guess it is possible.
The problem is those people who are using the same IP. Like people browsing from behind the same router.

The next-best would be to store information in the database (whatever "the database" is) and associate it with a user. The user has to log in to get their settings and information, but it's there.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Session is not available in different browser

Post by jackpf »

Yeah...that's what I meant by being a security risk. Unless the previous user explicitly logged out, the next user of the same IP address will have all their login info.

And yeah...but doesn't that defeat the point of transferring the session?

Surely the only reason you'd want to do this is so that a user doesn't have to log in multiple times in different browsers...
Post Reply