0

I have a Drupal site

mydomain.com/

Within a block full php I have the following:

<?php
session_start ();
echo json_encode($_SESSION['playlist']); 
?>

This code shows me correctly my array inside the session varible example:

[
    "{\"title\":\"emo\",\"artist\":\"a href=\",\"mp3\":\"\"}",
    "{\"title\":\"emo\",\"artist\":\"a href=\",\"mp3\":\"\"}",
    "{\"title\":\"Hablando Claro Pegando Fuerte\",\"artist\":\"\",\"mp3\":\"http://red.comppa.com/sites/default/files/audios/01%20radionovela%20hablando%20claro%20pegando%20fuerte.mp3\"}",
    "{\"title\":\"desobedicia\",\"artist\":\"a href=\",\"mp3\":\"\"}"
]

But if I have another file called getsession.php with the same code:

<?php
session_start ();
echo json_encode($_SESSION['playlist']); 
?>

Then I dirigo to mydomain.com/getsession.php and shows me:

null
Zaffy
  • 16,801
  • 8
  • 50
  • 77
laur
  • 500
  • 1
  • 9
  • 23

3 Answers3

1

solved with :

<?php
//set the working directory 
chdir('/home/www/mydrupal/');
define('DRUPAL_ROOT', getcwd());

//Load Drupal
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

echo json_encode($_SESSION['playlist']); 
?>
laur
  • 500
  • 1
  • 9
  • 23
0

Check the order that your files are being included. It is possible that you are trying to echo the values of the session before it has been set.

GaryDevenay
  • 2,405
  • 2
  • 19
  • 41
0

session_start

If a session fails to start, then FALSE is returned. Previously TRUE was returned. (Source)

Perhaps, content was sent to the browser BEFORE session_start was called. This will generate an error as a result!

More info here in a related post.

Community
  • 1
  • 1
Paul Calabro
  • 1,748
  • 1
  • 16
  • 33