Create a Redeem Page

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

  1. 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.
  2. Create a new page for if the validation code is invalid, name this page wrong to work with the code.
  3. 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
  4. Export your design and upload it to your server.
  5. Choose the page you want the validation code to be on and rename it from .html to .php.
  6. 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();
       }
   }
}
?>
  1. 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:

  1. First the script listens for the form submission and catches the validation_code text input submitted.
  2. The script then checks the contents of validation_code against the string stored in the correctCode variable
  3. If the code does not match, it directs the user to the wrong.html page.
  4. If the code does match, a cookie is created on the users computer called validation_success and they are directed to the success.php page.
  5. 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.
  6. If the cookie is not found, the user is again redirected to the wrong.html page.

Hope this helps!