Azeem Haider Azeem Haider - 25 days ago 8
PHP Question

Session is not working in different page

I create a

session
and try to access it from another page under same domain and directory but it is not working.

<?php
session_start();
error_reporting(E_ALL);
$_SESSION['abc'] = 'ajsdkla skjld ajsdlkja skld jasl';

echo $_SESSION['abc'];

?>


Code for second page

<?php
error_reporting(E_ALL);
session_start();
echo '<h1> Session = '.$_SESSION['abc'].'</h1>';
?>


You can also check it on live here is a page one link

And here is a second page link

When I try to access
session
on second page I found this error
Notice: Undefined index: abc


I really wonder why this is happing can you please check it.

Answer

Your live server (imube.com) responds with

Set-Cookie:PHPSESSID=c1eb78a09f6cfe7830d6d445f95fa748; path=/; domain=.sadishop.com

That's a php configuration problem, since the cookie's domain don't match. You can change that in runtime with session_set_cookie_params, example:

session_set_cookie_params(0, '/', '.imube.com');

or you can change the session.cookie_domain parameter in your php.ini configuration file and leaves it empty.