Lalita Tana Lalita Tana - 2 months ago 9
HTML Question

trying to redirect a user to a different link after an input was insert

I am learning PHP and HTML (sorry for being noob) trying to redirect a customers to a different link after an input was insert. which means after he press verify he will be redirect to my website www.example.com/home.php This is my current code:

<div class="tclpad" style="width:90px;">&nbsp;</div>
<div class="tclpad"><input class="bstd" value="Verify" type="submit"></div>


Also, when someone inserts a wrong information, i can see in the code:

<?php
if(isset($_SESSION['wrong'])) {
echo "<p class='error'>Authentication failed.</p>";
session_destroy();
}
?>


I want the user after he press verify will get a message 'Verified'.
Thank you so much guys for your help.

Answer

Check the accepted answer here: How to make a redirect in PHP?

I'm not sure exactly what you're looking for with the 'Verified' statement, but the answer above shows how to redirect the web page with the PHP header() function.

Edit: I realized the header() function limits how the current page provides feedback. Instead, you could use javascript to redirect:

function redirectOnVerify(myVar) { 
    if(myVar === 'success'){
         window.alert('You have verified successfully');
         window.location = 'http://newlocation.com' ;              
    }
    else if (myVar === 'failure') {
          window.alert('Failed to verify');
    }
    else {
       console.log('PHP auth error, neither success nor failure')
    }
}

And then in your html:

<input onClick="redirectOnVerify('
            <?php if(isset($_SESSION['right'])){ 
                   echo 'success'
                   }
                 else if (isset($_SESSION['wrong']){
                   echo 'failure'
                 }
                 else {}
            ?>
            ')">

/j

Comments