Anyone has ideas how?
You’re going to have to provide much more information about what your looking to achieve than this I’m afraid.
Try describing what this will be used for, how you imagine it will work and the expected end result. And maybe we can help.
Basically I’m creating a redeem page where you can reedeem a code And get a prize out of it first after it put their usernames in and then after that the redeem code that I usually give I was wondering how I could potentially do that.
Are you using your own hosting, or Bootstrap Studio’s hosting?
And how would you describe your knowledge of coding with JavaScript?
i use namecheap for my hosting
Ok!
So, you should be able to program something in PHP to validate your code.
I recently built a similar system to this and, if you would like I can share you my code.
I would gladly appreciate that!
Password protected page in PHP
Firstly, this script was made in mind of PHP 8, and I have not tested it on older versions of PHP - although no PHP 8 specific code is used it should be fine. I am also sharing this as it is and I cannot support the installation of this script, nor any changes you wish for it to have.
Steps
- Create your validation page and insert a form on this page with a submit button and create a text input and give it the name
validation_code
. - Create a new page for if the validation code is invalid, name this page
wrong
to work with the code. - Create the page you wish to be shown to the user if the validation code is correct. Name this page
success
to work with the code - Export your design and upload it to your server.
- Choose the page you want the validation code to be on and rename it from
.html
to.php
. - Above
<!DOCTYPE html>
paste the following code in:
<?php
// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validation code
$correctCode = "ValidationC0de";
// Check if the validation_code input exists in the form data
if (isset($_POST['validation_code'])) {
// Get the input value
$submittedCode = $_POST['validation_code'];
// Check if the submitted code matches the correct code
if ($submittedCode === $correctCode) {
// If correct, set a cookie with the name 'validation_success'
setcookie('validation_success', '1', time() + 3600, '/'); // Expires in 1 hour
// Redirect to the success page
header('Location: success.php');
exit();
} else {
// If incorrect, redirect to the error page
header('Location: wrong.html');
exit();
}
}
}
?>
- Next, rename the success page from
.html
to.php
and then insert this code like before:
<?php
// Check if the 'validation_success' cookie is set
if (isset($_COOKIE['validation_success'])) {
// Delete the 'validation_success' cookie so user cannot access the page again upon reload
setcookie('validation_success', '', time() - 3600, '/'); // Expire in the past to delete
} else {
// Redirect to the error page if no cookie is set
header('Location: wrong.html');
exit();
}
?>
How it works
This script is very simple, and it works in the following steps:
- First the script listens for the form submission and catches the
validation_code
text input submitted. - The script then checks the contents of
validation_code
against the string stored in thecorrectCode
variable - If the code does not match, it directs the user to the
wrong.html
page. - If the code does match, a cookie is created on the users computer called
validation_success
and they are directed to thesuccess.php
page. - The success page checks for the
validation_success
cookie. If it is found, it then expires this cookie so that the user cannot revisit the page after they reload the page. - If the cookie is not found, the user is again redirected to the
wrong.html
page.
Hope this helps!