Azeem Haider
Azeem Haider

Reputation: 1513

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.

Upvotes: 2

Views: 2590

Answers (3)

Rohit Sengar
Rohit Sengar

Reputation: 157

**Include some code in .htaccess file **

RewriteEngine On
php_flag output_buffering on

Upvotes: 0

Banu Priya
Banu Priya

Reputation: 61

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>';
?>

Upvotes: 0

Federkun
Federkun

Reputation: 36924

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.

Upvotes: 1

Related Questions