Hello all, I've been using Chrome to develop a database website for a school project and I've been having a couple of issues.

The first being refreshing. When I logout or login I have to refresh the page for it to pick it up. Or if sometimes I'm logged in but it thinks I'm logged in under a previous session until I refresh.

My second problem, which might not even be Chrome related but I don't think I've done it wrong... is SESSION variables. Well one session variable. So maybe it is wrong...

In my details.php I'm doing this to return the title of a book from a series of search results:

$title = $_GET['q'];
$_SESSION['title'] = $title;

and then over in requests.php I want to use that title so I do this:

$title = $_SESSION['title'];

But I keep getting an Unidentified value 'title' when I try to use $title in a query.

$requestCheck = mysql_query("SELECT holdsrequests.libraryID FROM holdsrequests, books WHERE books.title = '$title'") or die(mysql_error());

1) Show your login/logout code.
2) Show the exact error message. Does it really say "Unidentified value" -?

1) Login and Logout code below.

Okay first, when a user accesses the search page they are logged in as a default user so they can have minimal access to the database. This is done through a menu. Which is included in a div layer

<div id="banner">
			<span class="menuButton">
			<?php
				include 'C:\wamp\www\Catalogue\php\menu.php';
			?>
			</span>
		</div>

menu.php

<?php
	ini_set('session.cache_limiter','private');
	session_start();
	
	
	if(isset($_SESSION['username'])){
	//IF USERNAME IS ALL READY SET//
		@mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']) or die(@mysql_error());
		@mysql_select_db($_SESSION['db']) or die(@mysql_error());
		$username = $_SESSION['username'];
	//IF USERNAME IS NOT DEFAULT DISPLAY MENU FOR LOGGED IN USER//
		if($username !=  "default"){
			?>
			<input type='button' name ='home' value='home' onclick= "window.location='http://localhost/Catalogue/php/test2.php';">
			<?php 
			if($username == "admin"){?>
				<input type='button' name ='home' value='control panel' onclick= "window.location='http://localhost/Catalogue/php/adminControl.php';">
			<?php
			}	
			else{?>
			<input type='button' name ='home' value='control panel' onclick= "window.location='http://localhost/Catalogue/php/userPanel.php';">
			<?php
			}
			?>
			<input type='button' name='logout' value='logout' onclick= "window.location='http://localhost/Catalogue/php/logout.php';">
			<?php
		}
		else{
		//LOGGED IN AS DEFAULT DISPLAY LOGIN BUTTON//
			?>
			<input type='button' name ='login' value='login' onclick= "window.location='http://localhost/Catalogue/html/login.html';">
			<?php
		}
	}

	else{
	//USERNAME HAS NOT BEEN SET - LOG IN AS DEFAULT
		$_SESSION['username']="default";
		$_SESSION['password']="password";
		$_SESSION['hostname']="localhost";
		$_SESSION['db']="cataloguethree";
@mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']) or die(@mysql_error());
		@mysql_select_db($_SESSION['db']) or die(@mysql_error());
		$username = $_SESSION['username'];
	}
	?>

login.php

<?php
	//log out of default username
	session_start();
	$_SESSION=array();
	session_destroy();
	//log into username
	ini_set('session.cache_limiter','private');
	session_start();
	$_SESSION['username']=$_POST['username'];
	$_SESSION['password']=$_POST['password'];
	$_SESSION['hostname']="localhost";
	$_SESSION['db']="cataloguethree";
	@mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']) or die(@mysql_error);
	@mysql_select_db($_SESSION['db']) or die(@mysql_error);
	header("Location: http://localhost/Catalogue/php/test2.php");
?>

logout.php

<?php
	session_start();
	$_SESSION=array();
	session_destroy();
	ini_set('session.cache_limiter','private');
	header('Location:http://localhost/Catalogue/php/test2.php');
?>

2) I've actually just thought of a better way to do this that should work better than the session idea.

$title = $_GET;
$_SESSION = $title;

Where does the '$title' pass from ? Via form or url ? This statement may encounter the problem if there is no request for '$_GET'. Set the default value if there is no request for '$title'.

$title = (isset($_GET['q'])) ? $_GET['q'] : 'default_value';

I'm not sure that's what your problem. Hope this help.

functioning

<input type='button' name='logout' value='logout' onclick= "window.location='http://localhost/Catalogue/php/logout.php';">

does anyone else notice anything unusual about php href,
running on the wamp localhost

<?php include 'C:\wamp\www\Catalogue\php\menu.php'; ?>

hint:

<?php include('File:///C:/wamp/www/Catalogue/php/menu.php'); ?>
<?php include('http://localhost/Catalogue/php/menu.php'); ?>

both work :)

I'm still having the same refreshing issue even with the include correction made.

For example, if I log out, the logout button stays on screen until I refresh. I then have to refresh a second time to get the log in button to appear.

Member Avatar for diafol

how about just unsetting $_SESSION before destroy?

$_SESSION=array();

why?

You also have 2X session_start() in login.php

The logout is directly copied from one we did in class, I believe, it was last year so I dug up some old files.

So basically in the login what I did was copy the logout script so it would logout of the default user before logging into a different user. I'm not even sure if that needs to be done, honestly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.