Jump to content

Sessions are saving but not working


Recommended Posts

<?php
$login = file_get_contents("tpl/contents/login.html");

if(isset($submitlogin)){
//Query setup
$loginquery = "SELECT 
				UserID, 
				Password 
			FROM 
				Login 
			WHERE 
				UserID='".mssql_real_escape_string($username)."' AND 
				Password='".$password."'";
$loginresult = mssql_query($loginquery);
$countrows = mssql_num_rows($loginresult);

if($countrows == 1){
	$_SESSION['username'] = $username;
	$_SESSION['password'] = $password;

}
if($countrows != 1){
	$login .= "<span style='color:red'>Login Failed</span>";
}
}
echo $_SESSION['username'];
//Get template
$template = str_replace("%ucp%", $login, $template);
?>

 

Its included in a file where session_start(); has been used and I tested it with other ways too like

 

<?php
$_SESSION['username'] = "test";
echo $_SESSION['username'];
?>

When I remove $_SESSION['username'] = "test";

It doesnt echo it anymore

Try to make a new file, put the following code into it, and see what it returns:

<?php
session_start ();
var_dump ($_SESSION);

If it returns with undefined variable, then your session handler is not starting (or you have some other configuration issue). On the other hand, if it returns an empty array, then I suspect the problem is with the session cookie and/or session ID not being recognized.

array(0) { }

 

Thats what it returns

I am almost sure it must be in the PHP settings but I dont know what exactly it is.

It works on my laptop where I have set up my own webserver. But on the VPS (where the problem happens) I use appserv. And I used to have it earlier with appserv and he changed it either in the apache or php settings

Archived

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

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