Forum Moderators: coopster

Message Too Old, No Replies

session_register

         

dj_lysuc

9:09 pm on Nov 10, 2004 (gmt 0)

10+ Year Member



Sorry, I dont know much about PHP so my friend gave me the following script about a year ago for logging onto a website, I was going to use it on new site, but im getting errors using session_register.
From what I have read the variables need to be changed to $_SESSION. I have tried to use my little knowledge of coding but to no avail, so can someone help me change this script or provide something similar so it will work again?

Thanks in advance.

<?
session_start();
if ($permission!="yes") {
if ($HTTP_POST_VARS["password"]=="") {
?>
<html>
Please log-in below for access:
<form method="post" action="index.php">
<div align="center">Password:
<input type="password" name="password" size="15">
<input type="Submit" value="Submit">
</div>
</form>
</html>
<? } else {
$password=$HTTP_POST_VARS["password"];
session_start();
if ($password=="password"){ $permission="yes";}
session_register("permission");
if ($permission=="yes") {
$dbcon = mysql_connect("localhost","DB","password")or die("Database Connection Error: ".mysql_error());
if (!$page) $page =index;
include( 'includes/'.$page.'/setup.php' );
include( 'includes/page_header.php' );
include( 'includes/'.$page.'/content.php' );
include( 'includes/page_footer.php' );
mysql_close($dbcon); } else {?>
Access Denied
<? } } } else {
if (!$page) $page =index;
$dbcon = mysql_connect("localhost","DB","password")or die("Database Connection Error: ".mysql_error());
if (!$page) $page =index;
include( 'includes/'.$page.'/setup.php' );
include( 'includes/page_header.php' );
include( 'includes/'.$page.'/content.php' );
include( 'includes/page_footer.php' );
mysql_close($dbcon);
}?>

ergophobe

4:34 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld dj,

A couple of things. First, you only need to call session_start() once and earlier is generally less likely to cause problems than later.

Second, as for getting by without session_register(), it's quite easy. Instead of



$password= $HTTP_POST_VARS["password"];
if ($password == "password")
{
$permission="yes";
}
session_register("permission");

redundant session_start() deleted



$password= $_POST["password"];
if ($password=="password")
{
$permission="yes";
}
$_SESSION['permission'] = $password;

Note that I've also changed the post array from the old $HTTP_POST_VARS to the new and preferred $_POST superglobal post array.

Tom

dj_lysuc

12:04 am on Nov 13, 2004 (gmt 0)

10+ Year Member



Thanks Tom. Im not sure why the second session start is in there. You have been most helpful.

Andy