0

This may sound a bit catchy, but i want to access variable across sessions. I want to store a variable in a session and want to access it even after i navigate away from my website and come back some time later.

Thanks in advance :) Cheers..

4 Answers 4

1

You need a cookie for that. http://www.w3schools.com/PHP/php_cookies.asp

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

2 Comments

but i dont want to use a cookie here as i'm storing some sensitive info in there :) and not even DB as i want to make this implementation easy without DB .. can u see of any other indirect alternatives :) Thanks for ur reply..
You could encrypt the data before putting it in the cookie.
0

You can solve this problem with sessions in this tutorial you can get a little explain about that

Comments

0

PHP has a built in mechanism for using sessions: http://www.php.net/manual/en/book.session.php

here is a super simple example from their tutorial:

<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
  $_SESSION['count'] = 0;
} else {
  $_SESSION['count']++;
}
?>

Comments

0

The only way to do this with php is to use cookies because the only data stored in browser's storage are cookies.

setcookie("TestCookie", $value, time()+3600);  /* expires in 1 hour */

After you set the cookie you can get it's value until expiration time with referencing $_COOKIE automatic global variable.

echo $_COOKIE["TestCookie"];

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.