?
Solved

PHP sessions not work on Internet Explorer

Posted on 2012-08-21
13
Medium Priority
?
2,019 Views
Last Modified: 2012-08-22
I'm developing a small web application which comes with user logins managed with PHP sessions. All work fine on Chrome, FF but Internet Explorer open the application without any authentication. It seems it's not working with PHP sessions to manage the user login.

Can anybody please help with this.

Thanks!
0
Comment
Question by:sameeragayan
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 11

Assisted Solution

by:Slimshaneey
Slimshaneey earned 501 total points
ID: 38315541
It may be that you have cookies disabled on IE. Try this fiirst and see if that sorts it:

http://www.browserguides.com/internet-explorer/how-to-enable-cookies
0
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 38315544
If that doesnt work, can you describe how your authentication model works? It would seem quite odd and insecure that authentication would rely on cookies/sessions in any way, and is likely something that should be looked at.
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38315565
@Slimshaneey

It would seem quite odd and insecure that authentication would rely on cookies/sessions in any way,

Interested to know what the alternatives would be ...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:sameeragayan
ID: 38315577
Checked Cookies settings and IE has been set to accept all cookies. All I'm doing check user's login details with the database and create sessions variables.
0
 
LVL 60

Assisted Solution

by:Julian Hansen
Julian Hansen earned 498 total points
ID: 38315613
See this quote from here (http://stackoverflow.com/questions/306132/php-session-doesnt-work-with-ie)
Check the name of the server machine. IE has problems with machine names that contain '-' or '_' - they cannot maintain a session! I've had this problem twice in the past, and it always takes me weeks to figure out, and I'm shocked IE hasn't fixed it.
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 38315890
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38315941
@darren-w- you don't have to use your hands to drive your car either you can use your feet doesn't mean its a great idea.

Disabling cookies means the session id becomes part of the URL which has a bunch of implications - apart from being unsightly.
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 38316025
Well expect it could be hidden using url rewrite, anyway I suspect the implementation is incorrect,  sameeragayan can you show us your implementation?
0
 
LVL 2

Author Comment

by:sameeragayan
ID: 38316989
Check login
<?php
session_start();
if(isset($_SESSION['linkuser']) && ($_SESSION['linkuid'])){ 
	if(($_SESSION['linktimeout'] + 600) > time()){
	$invalid = FALSE;
	$_SESSION['linktimeout'] = time();
	}
	else{
	$invalid = TRUE;
	
	}
}
else{
	$invalid = TRUE;
}

if($invalid){
	header('location:log_in.php?msg=6baa83c3ccdfdf826e996761bea0530c');
}
	
       
?>

Open in new window

0
 
LVL 2

Author Comment

by:sameeragayan
ID: 38317000
<?php
include('./dbconn.php');

$username=$_POST['username']; 
$password=$_POST['password'];



$qry1="SELECT * FROM Users WHERE Username='$username' AND Password='$password'";
$rs1=odbc_exec($conn_sql, $qry1);
$row1=odbc_fetch_array($rs1);


if($row1 != FALSE){
	session_start();
	$_SESSION['linkuser'] = $username;
	$_SESSION['linkname'] = $row1['First_Name']." ".$row1['Last_Name'];
	$_SESSION['linkuid'] = $row1['UserID'];
	$_SESSION['linktimeout'] = time();
	
	$qry2 = "INSERT INTO Access_log (UserID, Username, Logon_time) VALUES('".$row1['UserID']."','".$row1['Username']."', GETDATE())";
	$rs2 = odbc_exec($conn_sql, $qry2);
	
	header('location:index.php');
}
else{
	header('location:log_in.php?msg=79cf2658af6a3381906066d7af4e412e');
}
		



?>

Open in new window

0
 
LVL 13

Accepted Solution

by:
darren-w- earned 501 total points
ID: 38318160
Hi, have setup a small test with the first script:

sessionseed.php:

<?php
session_start();
$_SESSION['linkuser']=true;
$_SESSION['linkuid'] = true;
$_SESSION['linktimeout'] = time();
$_SESSION['linktimeout']= time();
?>
<a href ="index.php">link</a>

Open in new window


index.php:

<?php

session_start();
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
$status = false;
if (isset($_SESSION['linkuser']) && ($_SESSION['linkuid'])) {
    if (($_SESSION['linktimeout'] + 600) > time()) {
        $status = false;
        $_SESSION['linktimeout'] = time();
    } else {
        $status = true;
    }
} else {
    $status = true;
}

if ($status) {
    echo "redirect";
    header('location:log_in.php?msg=6baa83c3ccdfdf826e996761bea0530c');
} else {
    echo "dont redirect";
}
	

Open in new window


and tested in ie8 and the session is passed fine

With the second one move session_start(); to the start right after the opening <?php tag
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38318297
NEVER put session_start() into a conditional code block.  It belongs at the top of the script, unconditionally in every script.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

HTH, ~Ray
0
 
LVL 2

Author Closing Comment

by:sameeragayan
ID: 38319438
HI All, Thanks you for providing information/advice on this matter. I checked it again this morning and it seems all working fine on IE. Yesterday I upgraded my IE to 9.  And I found several post and useful.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question