简体   繁体   中英

PHP - Header Location not working on mobile?

Expample Link: http://link.bisnis-id.com/?go=google

<?php if(isset($_GET['go'])) { ?>
<?php $link_id = $_GET['go']; ?> <!-- output = google -->

<!-- Short explanation: "google" is generating a link for google website -->
<?php $link_url = "https://www.google.com"; ?>

<?php header("Location: $link_url"); ?>
<?php exit; ?>
<?php } ?>

That link will redirect to https://www.google.com , but It is not redirecting when I access on mobile browser.

You can't output even a single output before the header.Also you should have only one starting and ending for this header.You can use ob_start() to. use the code below

    <?php if(isset($_GET['go'])) { 

     $link_id = $_GET['go'];
    $link_url = "https://www.google.com";
    header("Location: $link_url");
     exit;
   } 
?>

Hope this helps you

You do not have to break the PHP block.

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

<?php if(isset($_GET['go'])) {
    $link_id = $_GET['go']; //output = google 

    //Short explanation: "google" is generating a link for google website 
    $link_url = "https://www.google.com"; 

    header("Location: $link_url");
    exit; 
 }?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM