Jump to content

Sessions are saving but not working


Recommended Posts

The sessions do save I have checked the directory, but somehow it doesnt work at all. I cannot call the session after going to another page. I am sure the code is correct I have tested it on many ways. It must be my PHP or apache settings but I have no idea what and where it is.

 

post-127801-13482403665532_thumb.png

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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