0

I have a Variable with a dinamic value inside.

My problem is, I can't patch this Variable anywhere when I change to another PHP file. I tried to register this Variable in a XML file, into the mysql data base, with constants, and nothing works, the value of my Variable will always reset.

Is there a way for me to freeze that variable value and use it later?

Thanks in advance.

PS: i looked for weeks in here and other places. Because im human I might have failed to realise hiden anwsers. If for some reason this is a duplicate please indicate the post, im very tired by now I might not be thinking strait.

EDIT:

The code is:

$actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

I recieve page1.php?id=51

Then I use $id = $_GET['id'];

To get the ID value (51)

And this is the value I would like to "freeze" to use in page2.php because if I navigate to page2.php the $id is gone.

6
  • 2
    Can you supply some code to show what you mean. I'm not sure I understand your question. Commented Dec 21, 2017 at 19:52
  • What do you mean by "patch this variable when changing to another file" in this context? Commented Dec 21, 2017 at 19:53
  • 1
    persistent variable options: a file, a database; if its persistent to one user : session\coockie. if you need help with your chosen method, you need to show us the code used, and explain the issues you had with the code Commented Dec 21, 2017 at 19:53
  • You should store the $_GET['id'] into a session variable. Once you get to page 2 you can just retrieve the value. Commented Dec 21, 2017 at 20:26
  • What the hell! It did work LOL Why Havent I tried this before. Thank you uom-pgregorio Commented Dec 21, 2017 at 20:35

1 Answer 1

1

session :)

page 1

<?php
ob_start(); session_start();
?>
<?php

echo "<a href='page_1.php?id=51'>page_1.php?id=51</a>";
echo "<br />";
echo "<a href='page_2.php'>page_2</a>";
echo "<br /><br />";

if(!empty($_GET['id']))
{
   $id = $_GET['id'];
   $_SESSION['page_id'] = $id;
}

if(!empty($id))
{
   echo $id;
}

?>

page 2

<?php
ob_start(); session_start();
?>
<?php

echo "<a href='page_1.php?id=51'>page_1.php?id=51</a>";
echo "<br />";
echo "<a href='page_2.php'>page_2</a>";
echo "<br /><br />";

if(!empty($_SESSION['page_id']))
{
   $id = $_SESSION['page_id'];
}

if(!empty($id))
{
   echo $id;
}

?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.