Jump to content

Recommended Posts

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

_________________________________________

 

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

_______________________________________________

 

 

<?php

session_start();

$page = basename(htmlentities($_SERVER['PHP_SELF']));

$page = explode(".", $page);

if(!empty($_SESSION['user']) or ($page['0'] != $_SESSION['user'])){

header("Location: /");

die;

}

?>

 

the users html page content is here

 

 

 

anyone got any ideas where i am going wrong here?

 

 

thanks

 

 

sophia

Link to comment
https://forums.phpfreaks.com/topic/68437-problem-with-php-page-not-linking/
Share on other sites

hi darkfreaks :)

 

thanks for the reply

 

sorry if my post is a little confusing ... i dont really know that much about php

 

what is meant to be happening here is that when a user enters the username and password in the login page, the user then gets redirected to their own private part of the site

 

ie..

 

username: user1

password:pass1

 

username: user2

password: pass2

 

user "user1" logs on and then gets redirected to ../users/user1.php

user "user2" logs on and then gets redirected to ../users/user2.php

 

i cant get the blooming thing to work though :(

 

 

sophia

 

<?php
$_SESSION['user'] = $username;

if($username == "user1") || ($password == "pass1") { header("Location: /users/user1.php?user=$username");
} else {


if($username)== "user2" || ($password == "pass2")  { header("Location: /users/user2.php?user=$username");
}else{

if($username == "user3") || ($password == "pass3")  { header("Location: /users/user3.php?user=$username");
}else{

if($username == "user4") || ($password == "pass4")  { header("Location: /users/user4.php?user=$username");

}else{


if($username == "user5") || ($password == "pass5")  { header("Location: /users/user5.php?user=$username");

}else{


if($username == "user6") || ($password == "pass6")  { header("Location: /users/user6.php?user=$username");

}else{

if($username == "user7") || ($password == "pass7")  { header("Location: /users/user7.php?user=$username");

}else{
$message = "Your username and or password are incorrect.";} ?>

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.