Currently I have a variable which comes via the query string like: http://www.domain.com/?id=123 and on the homepage I can access this variable using $_GET['id'], but if I click on any page on the website I can not access this variable anymore, is there a way so that I can access this variable where ever I go on my website?
What's your url structure ( home.php or index.php?page=home ) ? There are only 2 options to save it - start a session or store it in cookie .. index.php?id=15 <?php // Start a new session session_start(); // Assign our id to the current session $_SESSION['id'] = $_GET['id']; ?> PHP: home.php ( no variable as you can see ) <?php // Open session session_start(); // Get our ID $id = $_SESSION['id']; // Print it out or do whatever you want with it echo "ID was : ".$id; ?> PHP:
You can use session or cookie to pass the info like ActiveFrost said. Session is just for the current session and will be destroyed once the browser is closed. Cookie can be stored for as long as you want (you decide), but will be destroyed if the user clears cookie. - ads2help