Solved

PHP Session broken after server (Linux Redhat) move

Posted on 2010-09-24
5
260 Views
Last Modified: 2013-12-12
I have a login section of my website that features a sessionvalidate.php script that is included on each page to make sure that a person is authorized to view the web page.  The server move was a lateral move with PHP 5 and MySQL 5 and Apache on both machines.  Obviously there is some PHP variable not turned on possibly?

Here is the code for the validate page that works on the original server and not on the new server.

<?Php
	session_start();
	include "../scripts/dbconnection.php";
	$myConn		= dbConnect();
	if(myConn==false)	header("Location: index.php?errCode=-3");
	
	$session_array=$HTTP_SESSION_VARS;
	if($session_array){
		$adminid	= $session_array['adminid'];
		$adminuser	= $session_array['adminuser'];
		$sql 		= "";
		$sql 		= "SELECT * FROM tbl_admin 
						WHERE user_uid='$adminid' AND
						username='$adminuser'";
		if(mysql_num_rows(mysql_query($sql,$myConn))<1)
		{
			header("Location: index.php?errCode=-4");
		}
	}else{
		header("Location: index.php");
	}
?>

Open in new window

0
Comment
Question by:pda4me
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:ziceva
ID: 33752425
You did not tell us what the actual error is ...
This is the script, but when you run it, where does it take you? index.php, index.php?errCode=-3 or index.php?errCode=-4?

Also, I would suggest using $_SESSION instead of $HTTP_SESSION_VARS ....
0
 

Author Comment

by:pda4me
ID: 33752466
ziceva, that worked!  I changed it to $_SESSION and its working fine?  Why is that, what is the difference?
0
 
LVL 7

Expert Comment

by:ziceva
ID: 33752587
$HTTP_SESSION_VARS is the deprecated version of $_SESSION (php4 or so)
0
 
LVL 7

Accepted Solution

by:
ziceva earned 500 total points
ID: 33752610
And a more complete answer

$_SESSION

$_SESSION variable is an associative array hold session variable available to the current script. This is automatic global variable also called super global variable. By default, this variable is available in all scopes throughout the script.

$HTTP_SESSION_VARS

Despite of $_SESSION variable, $HTTP_SESSION_VARS variable is not by default auto global but hold same information as $_SESSION variable. register_globals directive is required to set in php.ini file to make this variable available throughout the script.

So the register_globals was the culprit ... anyway, it is good practice to use $_SESSION instead of $HTTP_SESSION_VARS

0
 

Author Closing Comment

by:pda4me
ID: 33752645
Awesome help and one of the most complete answers I have ever had from an Expert.  Thanks for the help!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question