Home > OS >  Redirect a web link in php using header
Redirect a web link in php using header

Time:11-07

Help, how to open link like https://www.google.com using php header while code in local server? im using localhost

my php code:

<?php
    if(isset($_GET['kirim'])){
        header("Location: https://www.google.com/");
    }
?>

my html code:

<div >
                            <button type="submit" name="kirim" ><a href="crud/confirm-process.php" style="color:white">Reservation via Whatsapp</a></button>
                        </div>

and after i clicked the button always show blank page

blank page after clicked the button

i want open google.com link or whatsapp link after click the button

CodePudding user response:

In the form element of your HTML code you define the action of the data submission. In this case the method is POST and the URL of your action is your PHP file "crud/confirm-process.php":

HTML code

<form action='crud/confirm-process.php'  method='POST' >
<div >
<button type="submit" name="kirim" >Reservation via Google</button>
</div>
</form>

PHP code in crud/confirm-process.php

<?php
 if(isset($_POST['kirim'])){
    header("Location: https://www.google.com/");
 }
?>
  • Related