aF.
aF.

Reputation: 66697

What is the proper way to pass a variable when page refresh/reload using php?

I've a php page that refreshes every minute and on it an php array global variable that I use to compare values (before and after a page refresh).

But I've a problem, whenever the page is refreshed, the php array is resetted. I know that's because HTML is stateless but I want to mantain the state of this array.

How can I do that?

Upvotes: 0

Views: 1286

Answers (2)

periklis
periklis

Reputation: 10192

You're looking for sessions http://www.php.net/manual/en/book.session.php

<?php
session_start();
if (!isset($_SESSION['arr']['counter'])) {
 $SESSION['arr']['counter'] = 0;
} else {
 $SESSION['arr']['counter']++;
}
var_dump($_SESSION);
?>

Upvotes: 3

Jan Hančič
Jan Hančič

Reputation: 53931

You can use sessions, cookies, database, memcache, redis, files, ... take your pick.

Upvotes: 1

Related Questions