Lalita Tana Lalita Tana - 4 months ago 20
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 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:

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

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


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 = '' ;              
    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 {}