0

Expample Link: http://mywebsite.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.

2 Answers2

0

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

Utkarsh Dixit
  • 4,153
  • 3
  • 14
  • 36
  • That won't work either because even the returns between each `` line will cause the error. You need to just have a single `` at the end of the script. – komodosp Jan 14 '15 at 08:16
0

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; 
 }?>
Dmitry
  • 1,997
  • 1
  • 16
  • 33