user2852776
user2852776

Reputation: 61

How to pass value of variable from one page to another using header?

how can I pass the value of $_POST['login'] to variable $login, to use the value in the page home.php ? using this code:

header('location:home.php');

Upvotes: 0

Views: 1126

Answers (2)

zkanoca
zkanoca

Reputation: 9918

Use $_SESSION array.

if (!isset($_SESSION)) session_start();

$_SESSION['login'] = $_POST['login'];

After switching to the next page you can call SESSION variable with 'login' key using:

if (!isset($_SESSION)) session_start();

echo $_SESSION['login']; 

Upvotes: 0

OptimusCrime
OptimusCrime

Reputation: 14863

By using session-variables, like this:

<?php
session_start();
$_SESSION['login'] = $_POST['login'];
header('location:home.php');
?>

And

<?php
// Home.php
session_start();
$login = $_SESSION['login'];
?>

Upvotes: 3

Related Questions