Jump to content

[SOLVED] session_register and register_globals


bofett

Recommended Posts

I am trying to figure out how to keep my program working and turn off register_globals.  From what I have been reading it seems to be a simple change but I cant seem to get it to work.  for example...

 

//I think I have to change something like this
session_register("myuid");
//to
$_session["myuid"] = $myuid;
//then call
$_session["myuid"] 
//instead of
$myuid
//right?

 

Anyway, here is the code I am using now with register_globals=on (session_start() is being callid in common.php)

 

include("include/common.php");
if( $_POST['username'] && $_POST['password'] ){
	$failed = 1;
	$username = $_POST['username'];
	$password = $_POST['password'];
	$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
#		echo $query;
	$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
	if ( ($result) && (mysql_num_rows($result) > 0) ){
		$row = mysql_fetch_object($result);
		$adlogin = $row->username;
		$myname = $row->username;
		$adpassword = $row->password;
		$myuid = $row->uid;
#			echo $adlogin." ----".$adpassword."<br>";
		if ( ($username != $adlogin) || ($password != $adpassword) ){
			$failed = 1;
	 }else{
			$failed = 0;
			$loggedin = 1;
		        session_register("loggedin");
			session_register("myuid");
			session_register("myname");
   }
  }else{
		$failed = 1;
		$loginerror = "<font color='#FF0000'>Username or password incorrect.</font>";
	}
}

 

 

Thanks for all of the help!

session_register should only be used when register_globals is enabled. When its disabled you use the $_SESSION superglobal variable for reading/writing to your session.

 

<?php
// when dealing with session always call session_start()
session_start();

// assign new session variables
$_SESSION['my_var1'] = 'new value';
$_SESSION['my_var2'] = 'another value';

?>

 

Now to retrieve your session variables you use.

<?php
// again make sure you call session_start() when using $_SESSION variables
session_start();

// assign new session variables
echo 'SESSION Vars:<br />';
echo 'my_var1 = "'$_SESSION['my_var1'] . '"<br />';
echo 'my_var2 = "'$_SESSION['my_var2'] . '"<br />';

?>

 

Do note the $_SESSION supergloabl is case-sensitive just like $_POST, $_GET and $_COOKIE etc

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.