2

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.

Azeem Haider
  • 1,443
  • 4
  • 23
  • 41

3 Answers3

1

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.

Federkun
  • 36,084
  • 8
  • 78
  • 90
0
use the following code

biology.php

<?php
   session_start();
   error_reporting(E_ALL);
   $_SESSION['abc'] = 'ajsdkla skjld ajsdlkja skld jasl';
   echo $_SESSION['abc'];
   header('Location: video.php');
?>

video.php

<?php
  error_reporting(E_ALL);
  session_start();
  echo '<h1> Session = '.$_SESSION['abc'].'</h1>';
?>
Banu Priya
  • 61
  • 1
  • 1
  • 11
0

**Include some code in .htaccess file **

RewriteEngine On
php_flag output_buffering on
Rohit
  • 101
  • 7