| | |
undefined variable although register_session done
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I am creating a login sessin in php. In first part index.html takes in text for AUTH_NAME and password in AUTH_PASSWD.
In the login.php I set these variables as global with session_register("AUTH_NAME") and session_register("AUTH_PASSWD").
code: index.html
[PHP]
<html>
<center><h2>Login</h2>
<form action=login.php method="post">
<table align=center>
<tr><td>User</td> <td><input type=text name=AUTH_NAME size="20"></td></tr>
<tr><td>Password</td><td><input type=password name=AUTH_PASSWD size="20"></td></tr>
<tr><td><input type="submit" value="Login!"></td></tr>
</form>
[/PHP]
code: login.php
[PHP]
<?php
include("conf/conf.php");
if($pw=file($PWD_FILE)) $authenticated = 0;
session_register("AUTH_NAME");
session_register("AUTH_PASSWD");
for($i=0; $i<=count($pw); $i++)
{
$line = split(":", $pw[$i], -1);
$pass = chop($line[1]);
$salt = substr($pass, 0, 2);
$ToCompare=$AUTH_NAME.":".crypt($AUTH_PASSWD, $salt);
if(strcmp(trim($pw[$i]),$ToCompare)==0)
{
$authenticated=1;
echo $authenticated;
}
}
?>
[/PHP]
in the conf.php I set up the password file like:
$PWD_FILE = '.../www/users';
I try to use AUTH_NAME and AUTH_PASSWD in the next lines but error_log tells that these variables are undefined
.
Help
In the login.php I set these variables as global with session_register("AUTH_NAME") and session_register("AUTH_PASSWD").
code: index.html
[PHP]
<html>
<center><h2>Login</h2>
<form action=login.php method="post">
<table align=center>
<tr><td>User</td> <td><input type=text name=AUTH_NAME size="20"></td></tr>
<tr><td>Password</td><td><input type=password name=AUTH_PASSWD size="20"></td></tr>
<tr><td><input type="submit" value="Login!"></td></tr>
</form>
[/PHP]
code: login.php
[PHP]
<?php
include("conf/conf.php");
if($pw=file($PWD_FILE)) $authenticated = 0;
session_register("AUTH_NAME");
session_register("AUTH_PASSWD");
for($i=0; $i<=count($pw); $i++)
{
$line = split(":", $pw[$i], -1);
$pass = chop($line[1]);
$salt = substr($pass, 0, 2);
$ToCompare=$AUTH_NAME.":".crypt($AUTH_PASSWD, $salt);
if(strcmp(trim($pw[$i]),$ToCompare)==0)
{
$authenticated=1;
echo $authenticated;
}
}
?>
[/PHP]
in the conf.php I set up the password file like:
$PWD_FILE = '.../www/users';
I try to use AUTH_NAME and AUTH_PASSWD in the next lines but error_log tells that these variables are undefined
.Help
Last edited by slacke; Feb 11th, 2007 at 7:10 am.
•
•
Join Date: Jan 2007
Posts: 37
Reputation:
Solved Threads: 3
I haven't used session_register yet but I have done a login/logout feature and I only used "session_start();" and stored the variables in the $_SESSION variable.
In your case it would be:
At the start of the succeeding pages, just put in session_start(); and check $_SESSION['authenticated']. I suggest you don't keep the password as a session variable as it may pose as a security risk for the user and you only need the password for authentication anyway.
In your case it would be:
<?php include("conf/conf.php"); session_start(); if($pw=file($PWD_FILE)) $authenticated = 0; $_SESSION["AUTH_NAME"] = /*value of name*/ ; for($i=0; $i<=count($pw); $i++) { $line = split(":", $pw[$i], -1); $pass = chop($line[1]); $salt = substr($pass, 0, 2); $ToCompare=$AUTH_NAME.":".crypt($AUTH_PASSWD, $salt); if(strcmp(trim($pw[$i]),$ToCompare)==0) { $_SESSION['authenticated']=1; echo $_SESSION['authenticated']; } }
At the start of the succeeding pages, just put in session_start(); and check $_SESSION['authenticated']. I suggest you don't keep the password as a session variable as it may pose as a security risk for the user and you only need the password for authentication anyway.
Last edited by jblacdao; Feb 16th, 2007 at 12:21 am.
![]() |
Similar Threads
- undefined variable error (PHP)
- Variable scope/declaration/assignment query (PHP)
- Undefined variable: PHP_SELF (PHP)
Other Threads in the PHP Forum
- Previous Thread: IF Conditions
- Next Thread: $verbose... No idea yet, :-(
| Thread Tools | Search this Thread |
apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date display dynamic echo email error fcc file files folder form forms freelancing function functions google href htaccess html image include incode insert integration ip javascript joomla limit link login mail match menu method mlm mod_rewrite multiple mysql oop pageing pagerank paypal pdf php problem query radio random recursion recursiveloop remote script search server sessions sms smtp soap source space sql strip_tags subversion support! survey syntax system table template tutorial undefined update upload url validator variable video virus web window.onbeforeunload=closeme; youtube





