I have a page I only want accessed if someone clicks "submit" on a form. Why am I able to access the page when I type in the URL?
I have a page named "booking.inc.php" inside a folder marked "Private". Here is the PHP code I wrote to prevent someone accessing the page by typing in the URL unless they click a button with the attribute "submit" and the name "book"...
<?php
if (isset($_POST['book'])) {
echo "It works!";
}
else {
header("location: ../index.php");
}
The HTML page is named "booking.php" and is not in the Private folder.
<!DOCTYPE html>
<html>
<head>
<?php require "header.php" ?>
<title>My Website</title>
</head>
<body>
<form action="private/booking.inc.php" method="post">
<input type="text">
<input type="text">
<button type="submit" name="book">Submit</button>
</form>
</body>
</html>
When I enter in some text into the form and click "submit", I just get a white page and nothing else. No echo statement that says, "It works!" Also, when I type in the path into the browser to get to booking.inc.php, I also just get a blank white page instead of being directed to index.php.
What am I doing wrong?
source https://stackoverflow.com/questions/68552527/i-have-a-page-i-only-want-accessed-if-someone-clicks-submit-on-a-form-why-am
Comments
Post a Comment