skip to Main Content

Im making an email verification system on PHP in cPanel, and when i press register, it sends an email to me with a link like this "../verified.php?code=1cbb402a59e8ec26dac0", i would need to get the full link and would have to chop it so it leaves me with just the code "1cbb402a59e8ec26dac0" so i can check if the code exists in database and then verify the account.

So from this

../verified.php?code=1cbb402a59e8ec26dac0

To This

"1cbb402a59e8ec26dac0

Purchasing the hostings for the first time fried my brains, so would be thankful if anyone could help me,

2

Answers


  1. For getting the text after the code: in the link, you can use the PHP $_GET function. You can use this code in your verified.php to get the text after code:

    <?php
    if(isset($_GET['code']))
    {
      $Data=$_GET['code'];
    }
    else{
    echo "Invalid Email Verification";
    ?>
    

    Now the part after the code= gets stored in the variable Data.
    You can change that to your desired variable.

    Sometimes even when the code is set, it might be empty, so to check that, the empty() function in PHP can be used.
    You can add this code to your verified.php:

    <?php
    if (empty($Data))
    {
      echo "Invalid Verification ID";
    }
    else
    {
      echo "Email Verification Success";
      //your other codes to update it on the server
    }
    ?>
    
    Login or Signup to reply.
  2. Well you have chosen to pass parameters which will be available in the global $_GET[] (as opposed to $_POST[]).

    So in your verified.php you will need to examine for the presence of $_GET[‘code’] and take the appropriate action.

    Using $code = $_GET['code']; is very bad as you need to qualify it.

    At a minimum you would need to…

    <?php
    
    // Ternary to give $code a value to prevent undefined variable error.
    $code = isset($_GET['code']) ? $_GET['code'] : NULL; 
    
    if($code === NULL){
      // error
    } else {
      // Check its a valid code and take the appropriate action.
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search