Jump to content

Interesting Session problem with PHP5


remlabm

Recommended Posts

Just to note, this works fine with PHP4 we are upgrading to PHP5 and this is problem we are having.

 

This is based from viewin index.php.

 

First we include() some files, db_controllers, user controllers etc... The DB controller and user controller both set session variables no problems.

 

now heres the problem.. after the includes are done index.php does some php work.. it tries to set a session variable. we will call it $_SESSION[index_test].

 

Now if i check the session after the page has loaded.. (at the bottom) the session looks like it has updated to reflect the [index_test]. However. if we refresh.. do echo $_SESSION[index_test] or even a var_export... everything else is there... from the db_controller and user_controller... but the var we set in the index did not set.

 

as i said... works perfect in PHP4. i have checked for any thing that would close the session. i have compared php.ini files for session settings... all are the same.

 

(baffled)  ???

Link to comment
Share on other sites

You might need to give us a small example or otherwise, maybe a clearer description, I just found your question a little hard to follow.

 

You might try to make the way you access arrays valid though. ie...

 

$_SESSION['index_test']

 

instead of....

 

$_SESSION[index_test]

Link to comment
Share on other sites

nope usin session_start();

 

ill put up as much code as i can as this is a HUGE site with each page having tons of code....

 

index.php top part of code...

 

include("lib/php_header.php");

if(!$_SESSION[index_controller]){
$sess_debug = "index_controller";
$_SESSION[index_controller] = "Y";
}

 

ok php_header.php just starts the session and calls control pages:

 

session_start();

$include_dir = "*hiddne*/lib";
//load global functions
require_once $include_dir."/functions.php";

$requested_domain = "*hidden*.com";
$requested_page = $_SERVER['PHP_SELF'];
$referral_page = $_SERVER['HTTP_REFERER'];
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$accepted_types = $_SERVER['HTTP_ACCEPT'];
$ip_address = getip();
$date = date('Ymd');
$yesterday = date('Ymd', strtotime("-1 day"));
$time = date('His');
$date_time = $date.$time;
$cfg[date_time] = $date_time;
$match = preg_match("/^\/([A-z]*)\/*/i", $requested_page, $matches);
$menu_area = $matches[1];

//check to see if phone
//if(preg_match("/(text\/[A-z.]*wml)/i" , $accepted_types)){
//	header("Location: http://www.*hidden*.com");
//	die;
//}

if(detect_mobile_device()){
  header('Location: http://*hiddne*.com/');
  exit;
}

//Let's start it up
require_once $include_dir."/database_controller.php";
require_once $include_dir."/page_controller.php";
require_once $include_dir."/user_controller.php";
require_once $include_dir."/record_controller.php";
require_once $include_dir."/template_controller.php";

if(!$_SESSION[global_a_controller]){
$sess_debug = "global_a_controller";
$_SESSION[global_a_controller] = "Y";
}

 

as you can see controllers are loadded... we will use the user_controller.php for example:

if(!$user_id){
$user_id = $_SESSION[user_info][user_id];
}

//Rest user login.
if($cookie_value_site){
$cookie_sql = " OR r.cookie_value_site = '$cookie_value_site' AND r.user_id=s.user_id ";
}
$get_user_sql = "select * from `users_required` as r, `users_settings` as s where r.user_id = '$user_id' AND r.user_id=s.user_id $cookie_sql limit 1";
$user_array = $db_cons[db_site]->GetRow($get_user_sql);
if($user_array[user_id]){
$_SESSION[user_info] = $user_array;

//load phone info
$get_phone_sql = "select * from `users_phone_profile` where `profile_id` = '".$_SESSION[user_info][phone_profile_id]."' AND `user_id` = '".$_SESSION[user_info][user_id]."' limit 1";
$phone_array = $db_cons[db_site]->GetRow($get_phone_sql);
if($phone_array[profile_id]){
	$_SESSION[phone_info] = $phone_array;

	$area_code = substr($_SESSION[phone_info][phone_number], 0, 3);
	$prefix = substr($_SESSION[phone_info][phone_number], 3, 3);
	$number_last = substr($_SESSION[phone_info][phone_number], 6, 4);
	$_SESSION[phone_info][number_formated] = $area_code."-".$prefix."-".$number_last;

	if($phone_array[service_id]){
		$get_service_sql = "select * from `service_providers` where service_id = '".$phone_array[service_id]."' limit 1";
		$_SESSION[phone_info][service] = $db_cons[db_global]->GetRow($get_service_sql);
		$_SESSION[phone_info][service_name_formated] = $_SESSION[phone_info][service][name];
	}else{
		$_SESSION[phone_info][service_name_formated] = "Not Supported";
	}
	if($phone_array[phone_id]){
		$get_phone_sql = "select *, (select name from `phone_man` where man_id = p.man_id) as man_name from `phones` as p where p.phone_id = '".$phone_array[phone_id]."' limit 1";
		$_SESSION[phone_info][phone] = $db_cons[db_global]->GetRow($get_phone_sql);
		$_SESSION[phone_info][phone_name_formated] = $_SESSION[phone_info][phone][man_name]." ".$_SESSION[phone_info][phone][name];
	}else{
		$_SESSION[phone_info][phone_name_formated] = "Not Supported";
	}
}
}

 

 

as you can see it sets tons of session vars.... they work perfect...

 

now back to index.php... i set the var $_SESSION[index_controller] = "Y";  it never sets it to the session.

 

the $sess_debug is stuff i have been working with today to try to figure where exactly the session was dieing at.

Link to comment
Share on other sites

Try this in your index.php file.

 

<?php

include "lib/php_header.php";

echo "<pre>";
printf($_SESSION);
echo "</pre>";

if (!$_SESSION['index_controller']) {
  $sess_debug = "index_controller";
  $_SESSION['index_controller'] = "Y";
}

echo "<pre>";
printf($_SESSION);
echo "</pre>";
die();

?>

 

What output do you get?

Link to comment
Share on other sites

i let it set the var... then refresh and the var disappears.

 

Array
(
    [database_controller] => Y
    [page_controller] => Y
    [user_controller] => Y
    [record_controller] => Y
    [template_controller] => Y
    [global_a_controller] => Y
    [user_info] => Array
        (
            [user_id] => 8681985663
            [old_user_id] => 9943755114
            [privilege] => 9
            [banned] => N
            [group_id] => 0
            [name] => blah
            [pass] => blah
            [email] => blah
            [phone_profile_id] => 8807257646
            [carrier] => 2800136896
            [phone] => 2359522671
            [number] => blah
            [status] => N
            [expire] => 20070222
            [number_verify] => Y
            [email_verify] => Y
            [previews] => 0
            [downloads] => 0
            [ev_code] => 
            [nv_code] => 
            [cookie_value_site] => 24LN77NLE2JZHSSJHQJABL6E55IFX2W6BBP
            [cookie_value_wap] => 
            [reg_date_time] => 20030306000000
            [last_seen_date_time] => 20070918182840
            [last_forum_date_time] => 0
            [referral_code] => 4HZCKCJ
            [account_flags] => 
            [dl_option] => 36178
            [account_about_expire] => Y
            [account_expired] => Y
            [week_news_letter] => Y
            [month_news_letter] => Y
            [adult_female_ss] => Y
            [adult_male_ss] => Y
            [adult_misc_ss] => Y
            [adult_humor_ss] => Y
            [adult_text_jokes] => Y
            [language_filter] => Y
        )

)

Array
(
    [database_controller] => Y
    [page_controller] => Y
    [user_controller] => Y
    [record_controller] => Y
    [template_controller] => Y
    [global_a_controller] => Y
    [index_controller] => Y
    [user_info] => Array
        (
            [user_id] => 8681985663
            [old_user_id] => 9943755114
            [privilege] => 9
            [banned] => N
            [group_id] => 0
            [name] => blah
            [pass] => blah
            [email] => blah
            [phone_profile_id] => 8807257646
            [carrier] => 2800136896
            [phone] => 2359522671
            [number] => blah
            [status] => N
            [expire] => 20070222
            [number_verify] => Y
            [email_verify] => Y
            [previews] => 0
            [downloads] => 0
            [ev_code] => 
            [nv_code] => 
            [cookie_value_site] => 24LN77NLE2JZHSSJHQJABL6E55IFX2W6BBP
            [cookie_value_wap] => 
            [reg_date_time] => 20030306000000
            [last_seen_date_time] => 20070918182840
            [last_forum_date_time] => 0
            [referral_code] => 4HZCKCJ
            [account_flags] => 
            [dl_option] => 36178
            [account_about_expire] => Y
            [account_expired] => Y
            [week_news_letter] => Y
            [month_news_letter] => Y
            [adult_female_ss] => Y
            [adult_male_ss] => Y
            [adult_misc_ss] => Y
            [adult_humor_ss] => Y
            [adult_text_jokes] => Y
            [language_filter] => Y
        )

)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.