Reputation: 9794
All,
I have few html pages in my application which is on WAMP.
I needed an login page which on successful login would redirect the user to the other page in the application.
I am:
1> Not able to redirect. I have define the header('Location: /X/Y/abc.html')
. This is the relative path from the wamp home i.e. C:\wamp\www\
. I think there is a issue with the path being mentioned here.
2> On unsuccessful login, the user should be redirect to the same page. When I tried that using header('Location: '.$_SERVER['PHP_SELF'])
. Trying to execute the code gives me
So I have 2 folders essentially:
Folder Z contains the following HTML code named index.html
and abc.php
Folder /X/Y/ contains the actual application for which the authentication is set.
HTML Code:
<html>
<head>
<title>
Login
</title>
</head>
<body>
<form action="/Z/abc.php" method="post">
<table id="input">
<tr>
<td>Admin Username <input type="text" name="username"></td>
</tr>
<tr>
<td>Password <input type="text" name="passwd"></td>
</tr>
<tr>
<td><input type = "submit" id="submitButton"></td>
</tr>
</form>
</body>
</html>
PHP Code:
<?php
$username="ab";
$password="cd";
if (isset($_POST["username"]) && strcasecmp($username, $_POST["username"]))
{
header('Location: /X/Y/navigation.html');
}
?>
Executing the code doesn't redirect me to the navigation.html
but stops at abc.php i.e. the URL remaind: http://localhost:81/Z/validate.php
Upvotes: 0
Views: 2514
Reputation: 360702
You'd need to make your abc.php redirect back to the login page if the login isn't successful:
abc.php:
<?php
$username = 'ab';
$password = 'cd';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ((isset($_POST['username']) && ($_POST['username'] == $username)) &&
(isset($_POST['password']) && ($_POST['password'] == $password))) {
header("Location: /X/Y/navigation.html");
exit();
}
}
header("Location: login.html");
Upvotes: 1