Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi everyone
got a problem accessing/opening the users' page here
what is meant to happen;
the user logs on with user name and password
the submit button then opens the users page
ie:
username: user1
password : pass1
opens
user1.php
but it doesn't
this is the folder structure:
login/users/user1.php
login.php sits in the root of the 'login' folder
user1.php sits in the sub-folder 'users'
here is the code.......
_________________________________________
login.php
_________________________________________Code: Select all
<?php
session_start();
$message = "Please Log in.";
if(!empty($_POST['username']) and !empty($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
if(($username == "user1") and ($password == "pass1") or
($username == "user2") and ($password == "pass2") or
($username == "user3") and ($password == "pass3") or
($username == "user4") and ($password == "pass4") or
($username == "user5") and ($password == "pass5") or
($username == "user6") and ($password == "pass6") or
($username == "user7") and ($password == "pass7")){
$_SESSION['user'] = $username;
header("Location: /users/{$username}.php");
die;
}else{
$message = "Your username and or password are incorrect.";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Login</title>
</head>
<body>
<h1><?php echo($message); ?></h1>
<form action="<?php echo(basename(htmlentities($_SERVER['PHP_SELF']))); ?>" method="post" accept-charset="utf-8">
<p>Username:<input type="text" name="username" /></p>
<p>Password:<input type="password" name="password" /></p>
<p><input type="submit" value="Login →" /></p>
</form>
</body>
</html>user1.php
_______________________________________________
Code: Select all
<?php
session_start();
$page = basename(htmlentities($_SERVER['PHP_SELF']));
$page = explode(".", $page);
if(!empty($_SESSION['user']) or ($page['0'] != $_SESSION['user'])){
header("Location: /");
die;
}
?>anyone got any ideas where i am going wrong here?
thanks
sophia
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]