How i can direct user to a specific page if user name and pa

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
hasratjani
Forum Newbie
Posts: 1
Joined: Sat Nov 19, 2011 1:50 am

How i can direct user to a specific page if user name and pa

Post by hasratjani »

I want to direct user to courses.html if user name and password is correct and if incorrect wrong.html.
I tried this but every time even user name and password is correct or incorrect is goes to wrong.html.
Any body help me to fix this problem.
Thanks

Code: Select all

<?php

$id="";
$pw="";

if (isset($_post['id']))
{
$id =$_post['id'];
}

if (isset($_post['pw']))
{
$pw =$_post['pw'];
}

if($id=='myid' && $pw =='mypw') {
header('Location: courses.html');
}

else {
header('Location: wrong.html');
}

?>
Last edited by Benjamin on Sat Nov 19, 2011 5:10 am, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
Gopesh
Forum Contributor
Posts: 143
Joined: Fri Dec 24, 2010 12:48 am
Location: India

Re: How i can direct user to a specific page if user name an

Post by Gopesh »

Hi,make sure that files(courses,wrong) are on the same folder .if not give the correct path in the header() function.
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: How i can direct user to a specific page if user name an

Post by mikeashfield »

Try:

Code: Select all

<?php
if (isset($_POST['id'])) {
        $id=$_POST['id'];
        $pw=$_POST['pw'];
        if($id=='myid' && $pw =='mypw')  {
            header('Location: http://127.0.0.1/courses.html');     //Give the full web document root here.
    }
}
elseif (isset($_POST['id'] && $id!='myid' && $pw!='mypw')) {
    echo "You have entered an incorrect username and/or password. Please try again.";
    sleep(3);
    header('Location: http://127.0.0.1/wrong.html');     //Give the full web document root here.   
}
else {
    echo "You have not entered any valid information."
    sleep(3);
    header('Location: http://127.0.0.1/wrong.html');     //Give the full web document root here.
}
?>
Post Reply