GoodSp33d
GoodSp33d

Reputation: 6282

A link for previous page in current page

I was trying to display a link in a page which will point to previous page the user has visited in drupal . Previously i was using sessions

echo $_SESSION['back']
$_SESSION['back']=htmlentities($_SERVER['REQUEST_URI']);

This worked fine, but i was told to use variable_get and set in drupal and not to use sessions So i did this

global $prev_global;
$prev_global=variable_get($prev_page,$default='http://mysite.local');
variable_set($prev_page,htmlentities($_SERVER['REQUEST_URI']));
. . .
echo "PREV:".$prev_global;

But this always points to the current page being viewed , what went wrong here ?

Upvotes: 2

Views: 991

Answers (1)

user113292
user113292

Reputation:

I don't know who told you to use variable_get() and variable_set(), but consider never listening to them again. variable_get() and variable_set() act on global variables, not user-based variables.

You had it right the first time. Use $_SESSION: that's what it's there for.

Upvotes: 3

Related Questions