lundi 11 septembre 2017

PHP Header not working while setting session variable

I am trying to change the page using php after I set a session variable. I am calling the function from this code

 echo "<a href='index.php?id=";

          echo $row['id'];
          echo "'><img src='images/pic_1.jpg'

The function is the called properly and the variable is set but the page never redirects

    <?php 
      function getID() {
echo $_GET['id'];
session_start();
header("Location: home.php");
$_SESSION['id'] = $_GET['id'];

}

  if (isset($_GET['id'])) {
    getID();
  }
            ?>
  

I have tried both using the exact url and the file name but none work. How do I get to have both the page redirect and the $_SESSION['id'] variable to work?




Aucun commentaire:

Enregistrer un commentaire