-2

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.

2 Answers2

0

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

Community
  • 1
  • 1
jwoe
  • 56
  • 3
0

Use header() like

header("refersh: 2; url=page2url");

Refersh is a delay time here the page will redirect after 2 seconds if u don't want delay then either set refersh to 0 or do this

header("location=pag2url");