Hello,

I 've created a personal page 'custom.php', located at the root of my website (www/drupal/custom.php).
This page is called by a simple link : a href="/cust.php" ....

In this page I try to get session values, but I can't.
print($_SESSION) return me an error.
Notice: Undefined variable: _SESSION in C:\www\druapl\cust.php on line 5

Can someone explain how to get back global $_SESSION ?

Thanks in advance.

Comments

marcvangend’s picture

Try to add sesstion_start() to your script. http://php.net/manual/en/function.session-start.php

Balth’s picture

Hi,

I did it but it doesn't work.
This is my whole file cust.php

<?php
	session_start();
        //Debug line
	print("Session : ");print_r($_SESSION); 
	
	if (isset($_SESSION['themekey_theme']) && ($_SESSION['themekey_theme'] == 'theme-accessibilite'))
	{
		$_SESSION['themekey_theme'] ="";
	}
	else if (isset($_SESSION['themekey_theme']) && ($_SESSION['themekey_theme'] != 'theme-accessibilite'))
	{
		$_SESSION['themekey_theme'] ="theme-accessibilite";
	}
	else{
		$_SESSION['themekey_theme']="theme-accessibilite";
	}

	//Commented for debugging test
        /*$url= $_SERVER['HTTP_REFERER'];
	header('Location: '.$url);*/
?>

Aim of my code is just to add a variable 'themekey_theme' to my session and also switch the value of the variable on every call of the page.
However, with session_start(); I got a new empty session, it doesn't give me the current session of the web site.

A strange point is :
It seems that the session started with cust.php is persisted because it always remember the last value of the variable 'themekey_theme' and it switch it on every call.

Note : error appears only when session_start() is commented, otherwise I got

  • Session : Array ( [themekey_theme] => )
  • Session : Array ( [themekey_theme] =>"theme-accessibilite" )
marcvangend’s picture

I'm not a php session guru unfortunately... if session_start does not work, I would try drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION): http://api.drupal.org/api/function/drupal_bootstrap/6

Balth’s picture

Thank You !
It's exaclty what I needed.

marcvangend’s picture

Great. thanks for the feedback.