Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP sessions not working at all

Tags:

php

session

I have tested php sessions with this function

session_start();

$_SESSION['test'][] = time();

header('Content-type: text/plain');
print_r($_SESSION);

In theory, it should return one more array element each time I reload the page. But in my case, for some reason, it always displays a single element.

So I'm stuck, please help!

UPDATED

PHP version on my server is 5.3.13 Here is what i have in session section enter image description here

like image 435
artnikpro Avatar asked Jun 10 '13 18:06

artnikpro


People also ask

How do I keep a PHP session alive?

Using ajax you can call a php script that refreshes your session every 10 minutes. :) This is as far as i can go to "exact". <? php session_start(); // store session data if (isset($_SESSION['id'])) $_SESSION['id'] = $_SESSION['id']; // or if you have any algo. ?>

What does $Session do in PHP?

A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer.

How do I start a PHP session?

Starting a PHP Session A PHP session is easily started by making a call to the session_start() function. This function first checks if a session is already started and if none is started then it starts one. It is recommended to put the call to session_start() at the beginning of the page.


1 Answers

A workaround to try...

session_start();

if(isset($_SESSION['test'])){
array_push($_SESSION['test'], time());}
else {
$_SESSION['test']= time();}

header('Content-type: text/plain');
print_r($_SESSION);

If this doesn't work as well...then you may not have cookies enabled...

like image 188
Kylie Avatar answered Oct 18 '22 01:10

Kylie