I'm using header()
to pass var user
from one page to another as:
header( "Location: temp.php? user = $user" );
the variable is getting passed and is shown on the url of another page.
But i dont know how to use these var user
in that page. Please help.
if the 'other page' is in PHP, you only need to:
$user=$_GET['user'];
EDIT: If you are not sure if you will receive 'user' and want to avoid error messages you should do:
if(isset($_GET['user'])){
$user=$_GET['user'];
}else{
//user was not passed, so print a error or just exit(0);
}
if you are using this to pass value
header( "Location:temp.php? user = $user" );
then on temp.php you have to use
$var=$_GET['user'];
to get the value and now $var contains the value you passed.
page1.php
<?php
$user = "batman";
header("Location:temp.php?user=".$user);
exit();
?>
temp.php?user=batman (you have just been redirected here)
<?php
if($_GET){
echo $_GET['user'] // print_r($_GET);
}else{
echo "Url has no user";
}
?>
Or you could use a $_SESSION - but this could easily complicate things
page1.php
<?php
session_start();
$_SESSION['user'] = "batman";
header("Location:temp.php);
exit();
?>
temp.php
<?php
session_start();
echo $_SESSION['user'];
unset($_SESSION['user']); // remove it now we have used it
?>