problem with php page not linking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sophia_
Forum Newbie
Posts: 1
Joined: Fri Sep 07, 2007 7:03 pm

problem with php page not linking

Post by 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]


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 &rarr;" /></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;
}
?>
the users html page content is here



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]
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

why the directory structure

Post by yacahuma »

Why the directory structure?


Why are you using usernames and passwird in the page instead of a database??
josa
Forum Commoner
Posts: 75
Joined: Mon Jun 24, 2002 4:58 am
Location: Sweden

Post by josa »

Try this:

Code: Select all

header("Location: ./users/{$username}.php");
But I think the correct way is to use an absolute uri. Something like this:

Code: Select all

header("Location: http://www.yoursite.com/login/users/{$username}.php");
/josa
Post Reply