Question

I have this code my friend sent me through a tutorial for a project;

<?php include 'includes/menu.php'; ?>
    <h1>Activate your account</h1>
    <?php

    if (isset($_GET['success']) === true && empty ($_GET['success']) === true) {
        ?>
        <h3>Thank you, we've activated your account. You're free to log in!</h3>
        <?php

    } else if (isset ($_GET['email'], $_GET['email_code']) === true) {
        $email      =trim($_GET['email']);
        $email_code =trim($_GET['email_code']); 

        if ($users->email_exists($email) === false) {
            $errors[] = 'Sorry, we couldn\'t find that email address';
        } else if ($users->activate($email, $email_code) === false) {
            $errors[] = 'Sorry, we have failed to activate your account';
        }

        if(empty($errors) === false){

            echo '<p>' . implode('</p><p>', $errors) . '</p>';  

        } else {
            header('Location: activate.php?success');
            exit();
        }

    } else {
        header('Location: index.php');
        exit();
    }
    ?>

Basically it activates your acc based on email and email code obviously, the email is; test@test.com and code is; code_536203131f86d3.07314347 how would i activate. Something like domain.com/activate?code_536203131f86d3.07314347 or?

Was it helpful?

Solution

PHP's $_GET variables are sent through the HTTP request's query string. So, your URL would be something like this:

domain.com/activate.php?email=test@test.com&email_code=code_536203131f86d3.07314347

Your two variables would then be accessible through the superglobal:

$_GET['email']
$_GET['email_code']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top