Page 1 of 1

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

Posted: Sat Nov 19, 2011 2:01 am
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');
}

?>

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

Posted: Sat Nov 19, 2011 2:37 am
by Gopesh
Hi,make sure that files(courses,wrong) are on the same folder .if not give the correct path in the header() function.

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

Posted: Sun Nov 20, 2011 4:21 pm
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.
}
?>