Shogikishi
05-14-2008, 03:07 AM
Hi,
I am trying to do something simple - store a value in a session variable and retrieve that variable value for use in another php page's script.
The code I have written instantiates a session and stores the user name of whoever logs in to Drupal. Since I developed this code outside of Drupal I have simply used a "session_start()" command and hard-coded a value into the session variable since there is no $user->name to access without being in Drupal. As it is right now, the index.php page starts a session, stores a value into the $_SESSION variable, and I confirm it fills the variable since I can echo/print the variable at the top of the page. Other php pages are able to access the session variable and run their scripts correctly. The thing is, when I drop index.php into Drupal, the $_SESSION variable does not pass to other PHP pages. The only page where it seems to be working is the index.php page in which it was instantiated.
What can I do to 1) capture and store the user's login name and 2) retrieve the user's login name for use in other PHP scripts?
The first PHP page (index.php) takes a user's name and stores it in session variable. Right now, the session variable is hard coded to be username=SHOGIKISHI. In Drupal, $user->name pulls the login username and so that is what goes into the session variable(evidenced by what prints on screen).
below is snippet:
<?php
# PHP CONFIG
session_start();
ini_set("display_errors",1);
ini_set("register_globals",1);
error_reporting(E_ALL);
//global $user; //enable in Drupal
//$_SESSION['username']=$user->name; //enabled when in Drupal
$_SESSION['username']="SHOGIKISHI"; //disable when in Drupal
in a code-behind PHP page, the username is needed to run SQL queries. When "session_start()" is used and the username is hard-coded, the value is stored in session variable and the variable is retrievable in all php pages, but only if these pages are not dropped in Drupal. When the pages are dropped into Drupal, the variable doesn't pass even if the value is hard coded. It's as if the variable is empty to all PHP pages except the page in which it is instantiated.
below is snippet of another PHP page (test.class.php) retrieving the session variable for use in other PHP scripts:
<?php
if (!isset($_SESSION)) {
// session is not started.
session_start();
}
# include ajaxcore class
require_once("AjaxCore.class.php");
###other code
##################
# Pass variable $user->name to code-behind page
#################
$UserName = $_SESSION['username'];
What can be done to capture login user's name and pull that value in other PHP pages? I'm not partial to the $_SESSION approach, but it seemed like the right way to do it. I'm just not able to do it right. I'm thinking there is a conflict with the "session_start()" command in my code and the fact that there is already a session running as part of Drupal? Help please?
I am trying to do something simple - store a value in a session variable and retrieve that variable value for use in another php page's script.
The code I have written instantiates a session and stores the user name of whoever logs in to Drupal. Since I developed this code outside of Drupal I have simply used a "session_start()" command and hard-coded a value into the session variable since there is no $user->name to access without being in Drupal. As it is right now, the index.php page starts a session, stores a value into the $_SESSION variable, and I confirm it fills the variable since I can echo/print the variable at the top of the page. Other php pages are able to access the session variable and run their scripts correctly. The thing is, when I drop index.php into Drupal, the $_SESSION variable does not pass to other PHP pages. The only page where it seems to be working is the index.php page in which it was instantiated.
What can I do to 1) capture and store the user's login name and 2) retrieve the user's login name for use in other PHP scripts?
The first PHP page (index.php) takes a user's name and stores it in session variable. Right now, the session variable is hard coded to be username=SHOGIKISHI. In Drupal, $user->name pulls the login username and so that is what goes into the session variable(evidenced by what prints on screen).
below is snippet:
<?php
# PHP CONFIG
session_start();
ini_set("display_errors",1);
ini_set("register_globals",1);
error_reporting(E_ALL);
//global $user; //enable in Drupal
//$_SESSION['username']=$user->name; //enabled when in Drupal
$_SESSION['username']="SHOGIKISHI"; //disable when in Drupal
in a code-behind PHP page, the username is needed to run SQL queries. When "session_start()" is used and the username is hard-coded, the value is stored in session variable and the variable is retrievable in all php pages, but only if these pages are not dropped in Drupal. When the pages are dropped into Drupal, the variable doesn't pass even if the value is hard coded. It's as if the variable is empty to all PHP pages except the page in which it is instantiated.
below is snippet of another PHP page (test.class.php) retrieving the session variable for use in other PHP scripts:
<?php
if (!isset($_SESSION)) {
// session is not started.
session_start();
}
# include ajaxcore class
require_once("AjaxCore.class.php");
###other code
##################
# Pass variable $user->name to code-behind page
#################
$UserName = $_SESSION['username'];
What can be done to capture login user's name and pull that value in other PHP pages? I'm not partial to the $_SESSION approach, but it seemed like the right way to do it. I'm just not able to do it right. I'm thinking there is a conflict with the "session_start()" command in my code and the fact that there is already a session running as part of Drupal? Help please?