Hi everyone,

I'm embarrased to ask as I am so new at this but here goes anyway: I have been trying to create a simple secure login screen that when successfully logged into, will allow the user access to other services. I found, modified a good tutorial and all works well. But the problem arises when I login and then try to move onto a new page. The example tutorial has a link to follow and presently displays a message but I cannot for the life of me change it without causing errors such as 'parser' errors etc.

I have tried several options suggested from this forum but as I do not know what I am doing believe I have probably made a mess of it. I include the index.php code as its very short and sweet. Could somebody please possibly help me with a way forward with this.

code:

<? ob_start(); ?>
<?php
//start the session so you would stay logged in
//always must be on top
session_start();
//include config.php file
include('config.php');
echo '<center><img src="gt-navy-logo.bmp" width="166" height="76"</center>';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The site</title>
</head>
<body>
<br><br>
<center><a href="?p=idx">Home</a> - <a href="?p=page">Access GT Intranet</a>
<?php
$p=$_GET['p'];
switch($p){
default:
//if user isn't logged in lets show him the log in form
if(!isset($_SESSION['username'])){
?>
<form action='login.php' method='POST'>
Username: <input type='text' name='username'><br>
Password: <input type='password' name='password'><br>
<input name="login" type="submit" value="Submit"><br>
</form>
<?}
else{
//$_SESSION['username'] = the current users 
//username. It will be echoed like "Hi, user!"
echo "<br><br>Hi, ".$_SESSION['username']."! ";
echo "<a href='logout.php'>Log out</a>";}
break;
case 'page':
//you can use it like this or use include()
if(!isset($_SESSION['username'])){
echo '<br><br>Log in to see this page!';}
else{
echo '<br><br>Only user who is logged in can see this!..and you see this so this means you are logged in;]';
}
}
?>
</center>
</body>
</html>
<? ob_flush(); ?>

ensure that you have session_start() at the beginning of each page so that your $_SESSION variables are passed.

Hi ardav,

I've checked all pages concerned and they all have the session_start() parameter at the beginings of each page. I think I've managed to crack it, I used the command:

header("Location: <web address & page>);

after the 'else' condition of the script, this worked, don't ask me why or how! Maybe my original question was badly written - for that I apologise. I probably need a php course or book for dummies.

many thanks for your help

regards

Jon

This question has already been answered. Start a new discussion instead.