0

I have a page [page A] that sends variable values to another page[page B]. Currently, I have been using the $_GET method to get the values from [page A] on [page B]. This is how the url in [page A] looks like

$id=2; <a href="pageB.php?id=$id">Goto Page B</a>

and on [Page B]

$id=$_GET['id'];
echo $id;

In this way I perfectly receive the value of the id from [page A] on [page B].

My questions is, would be possible to receive the value of the id from [page A] onto [page B] without adding ?id=$id to the url in [page A] ?

Please if yes, how can I do this. Thanks

George
  • 1,086
  • 14
  • 48
  • 2
    You'll need to use [sessions](http://www.w3schools.com/php/php_sessions.asp), plenty of [tutorials](http://www.php.net/manual/en/function.session-start.php) online. Or [cookies](http://www.php.net//manual/en/features.cookies.php). Sessions would be better. – scrowler Jun 23 '14 at 23:25

2 Answers2

3

You can use a $_SESSION variable, which will be available on every page once activated:

Page A:

<?php
    session_start();
    $_SESSION['id'] = 2;
?>

Page B:

<?php
    session_start();
    if (isset($_SESSION['id']))
        echo $_SESSION['id']; // 2
?>
Mark Miller
  • 7,442
  • 2
  • 16
  • 22
  • 2
    Just an advice: Try to check if var really exists `isset($_SESSION['id'])` because user may block cookies or delete them before going to Page B. – Zerquix18 Jun 23 '14 at 23:27
  • Aryt thanks..I was making a research and i found this answer,i want to know if sessions are preferred to this answer http://stackoverflow.com/a/1244331/2595059. – George Jun 23 '14 at 23:40
  • @George I would certainly prefer sessions over that answer. Seems unnecessarily complex for what you're trying to do. – Mark Miller Jun 23 '14 at 23:44
-1

you want to use sessions here:

session_start(); 
$_SESSION['id']= $id;

$id can of course be any value.

schnabler
  • 687
  • 7
  • 23