Hello, I'm having a totally brain freeze on how to do something that I believe is relatively simple but I'm having such a stupid moment that I don't even know what to google at the moment.

What I'm creating is a book catalogue for a school project.

It opens to a start page and I was thinking of using some default username to allow access to the database.

What I need is for this default username to be overwritten if a person logs in.

ie: I'm at the search page, I hit the login and get redirected to my control panel. The control panel has a link back to the search page.

The search pages allows access to the database with a default user that had limited privileges. If a person has logged in I need it to change these variables to whatever they are currently logged in as and change the 'login' button to 'logout'. And I'm entirely blanking on how to do this, I can't even form a simple sentence to search in google... It's rather early I think my brain is still asleep.

Anyway thanks for the help. Sorry if its incoherent.


Oh code would probably be nice, I know it doesn't work this way since I have the values hard coded. Like I said, brain freeze.

<?php
	include 'C:\wamp\www\Catalogue\html\Search.html';
	ini_set('session.cache_limiter','private');
	session_start();
	$_SESSION['username']="default";
	$_SESSION['password']="password";
	$_SESSION['hostname']="localhost";
	$_SESSION['db']="bookcatalogue";
	
	
	@mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']) or die("Access to db server denied");
	@mysql_select_db($_SESSION['db']) or die("Access to library denied");
	$username = $_SESSION['username'];
	if($username == "admin"){
		echo "<div class=\"menubar\"><a href = \"http://localhost/logout.html\"></div>";
	}
	else{
		echo "<div class=\"menubar\"><input type='button' name='Login' value='login' onclick= \"javascript:toggleLayer('loginBox');\"></div> ";
		
		}
?>

Why not "log out" of the default user and then "login" to the admin account.
End the default session just like you're logging out of a regular account, and then have it login to the admin account right after.

As per i understood your problem...this is what you want to do.....
form.php

<form action="login.php" method="POST">
Enter Username<input type="text" name='username'>
Enter Password<input type="text" name='password'>
<input type="submit" value="submit" name="submit">
</form>

login.php

<?php
	include 'C:\wamp\www\Catalogue\html\Search.html';
	ini_set('session.cache_limiter','private');
	session_start();
if(isset($_POST['name']))
{
$_SESSION['username']=$_POST['username'];
	$_SESSION['password']=$_POST['password'];
	$_SESSION['hostname']="localhost";
	$_SESSION['db']="bookcatalogue";
}
else
{	
$_SESSION['username']="default";
	$_SESSION['password']="password";
	$_SESSION['hostname']="localhost";
	$_SESSION['db']="bookcatalogue";
 }
 
	@mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']) or 
die("Access to db server denied");
	@mysql_select_db($_SESSION['db']) or die("Access to library denied");
	$username = $_POST['username'];
echo "Welcome".$username;
	 if($username == "default"){
		echo "<form method='POST'>";
		echo "<input type='submit' value='login' name='submit'>";
		echo "</form>";
	}
	else{
		echo "<form method='POST'>";
		echo "<input type='submit' value='logout' name='submit'>";
		echo "</form>";
 
		}
?>

If i missed some thing that you require let me know...i will help you to accomplish it....
IF YOUR PROBLEM IS SOLVED MARK IT READ AND NOTIFY IT WHETHER IT WAS USEFUL OR NOT....

that's very close to what I need I think: here's what I have,

I start with start.php which is a search page with a login button up the corner which unhides the login form when clicked

<?php
	include 'C:\wamp\www\Catalogue\html\test2.html';
	ini_set('session.cache_limiter','private');
	session_start();

	if(isset( $_SESSION['username'])){
		$username = $_SESSION['username'];
		if($username !=  "default"){
			echo "<div class=\"menuButton\"><a href = \"http://localhost/logout.html\"></div>";
		}
	}
	else{
		$_SESSION['username']="default";
		$_SESSION['password']="password";
		$_SESSION['hostname']="localhost";
		$_SESSION['db']="bookcatalogue";
		@mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']) or die("Access to db server denied");
		@mysql_select_db($_SESSION['db']) or die("Access to library denied");
		echo "<div class=\"menubar\"><input type='button' name='Login' value='login' onclick= \"javascript:toggleLayer('loginBox');\"></div> ";
	}
?>

I click the login button and that brings up the login form, I login and hit submit

login script:

<?php
	include 'C:\wamp\www\Catalogue\html\adminControl.html';
	ini_set('session.cache_limiter','private');
	session_start();
	$_SESSION['username']=$_POST['username'];
	$_SESSION['password']=$_POST['password'];
	$_SESSION['hostname']="localhost";
	$_SESSION['db']="bookcatalogue";
	
	
	@mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']) or die("Access to db server denied");
	@mysql_select_db($_SESSION['db']) or die("Access to library denied");
	$username = $_SESSION['username'];
	if($username == "admin"){
		
		echo "<div class=\"menuButton\"><a href = \"http://localhost/logout.html\"></div>";
	}
?>

on the adminControl.html page I have this link

tr>
<td width="19%"><button onClick="window.location='http://localhost/Catalogue/php/start.php'"><img src="\Catalogue\images\Token_by_brsev\Token Light\TokenW-PNG\OS+Folders\Search.png" /></button></td>
<td width="81%">Search</td>
</tr>

this should take me back to search BUT start.php should check is the SESSION variable has been set and act accordingly. Which is doesn't seem to be doing.

This is probably a little convoluted at the moment as I tend to jump into things with no real direction... as you can see that's totally working for me o.o

okay, lol I figured the problem. the html being echoed in my php script is getting added to the end of the html file. If I check the source code in my browser I get this:

<div id="footer">



</div>
</body></html>


<div id="banner"><span class="menuButton"><a href = "http://localhost/logout.html"></span></div>

Trouble is that banner needs to go at the very top of the page... either way I know what's wrong now, it just might take some reworking to get it all outputting properly.

success! the only trouble now is it I have to manually refresh the page to get it to update which button is shown...

ok...it seems like now your problem is solved....The code i gave was according to what i interpreted from your problem....

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.