Hi guys. I'm just started with php.
I'm assigned to do a login page using the example below. When I use this example, I cannot complete my program because an error occured said that "argument 1 is missing"
I've tried to solve the error, but I failed. Help me please.Thank you.
<HTML>
<HEAD>
<TITLE>gft</TITLE>
</HEAD>
<BODY BGCOLOR=#9CCFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<?
//session_start();
/**
Checks whether or not the given username is in the
database, if so it checks if the given password is
the same password in the database for that user.
If the user doesn't exist or if the passwords don't
match up, it returns an error code (1 or 2).
On success it returns 0.
/
function confirmUser($userno, $password){
global $conn;
/ Add slashes if necessary (for query) */
if(!get_magic_quotes_gpc()) {
$userno = addslashes($userno);
}
/ Verify that user is in database /
$q = "SELECT password FROM user WHERE userno = '$userno'";
$result = mysql_query($q,$conn);
if(!$result || (mysql_numrows($result) < 1)){
return 1; //Indicates username failure
}
/ Retrieve password from result, strip slashes /
$dbarray = mysql_fetch_array($result);
$dbarray['password'] = stripslashes($dbarray['password']);
$password = stripslashes($password);
/ Validate that password is correct /
if($password == $dbarray['password'])
{
return 0; //Success! Username and password confirmed
}
else{
return 2; //Indicates password failure
}
}
/**
checkLogin - Checks if the user has already previously
logged in, and a session with the user has already been
established. Also checks to see if user has been remembered.
If so, the database is queried to make sure of the user's
authenticity. Returns true if the user has logged in.
/
function checkLogin(){
/ Check if user has been remembered /
if(isset($COOKIE['cookname']) && isset($COOKIE['cookpass'])){
session_start();
$SESSION['userno'] = $COOKIE['cookname'];
$SESSION['password'] = $COOKIE['cookpass'];
}
/ Username and password have been set /
if(isset($SESSION['userno']) && isset($SESSION['password'])){
/ Confirm that username and password are valid /
if(confirmUser($SESSION['userno'], $SESSION['password']) != 0){
/ Variables are incorrect, user not logged in /
unset($SESSION['userno']);
unset($SESSION['password']);
return false;
}
return true;
}
/ User not logged in /
else{
return false;
}
}//check login
/**
Determines whether or not to display the login
form or to show the user that he is logged in
based on if the session variables are set.
/
function displayLogin($msg){
global $logged_in;
if($logged_in){
global $conn;
$sql = 'UPDATE counter SET counter = counter+1';
$result = mysql_query($sql,$conn);
include("soundlibrary.php");
main();
include("log.php");
$msg = '';
displayLogin($msg);
die("");
}
else{
?>
<form action="" method="post">
<TABLE ID="Table_01" WIDTH=619 HEIGHT=600 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<tr align="center" valign="top">
<td height="80"><? echo "<br><strong><font size='1' face='Arial' color='#990000'>".$msg."</font></strong>"?></td>
</tr>
<tr valign="top" align="center">
<td height="138"><font face="Arial, Helvetica, sans-serif"><b><font size="2" color="#333333">mobile
# :
<input type="text" name="user" size="12">
<br>
<br>
password :
<input type="password" name="pass" size="12" maxlength="10">
<br>
<br><!--Sorry...our system is currently undergoing maintainance.-->
<input type="submit" name="sublogin" value="lets go :o)">
</font></b></font></td>
</tr>
<tr align="center" valign="top">
<td height="30"> </td>
</tr>
<tr align="center" valign="top">
<td><font face="Arial, Helvetica, sans-serif"><b><font size="2" color="#333333">
<input type="text" name="registerpassword" size="15">
</font></b></font> <b><font color="#333333" size="2" face="Arial, Helvetica, sans-serif">
</font></b>
<input type="submit" name="registersubmit" value="click me">
</form>
<!-- End ImageReady Slices -->
<?
}//else
}//function displayLogin()
/**
Checks to see if the user has submitted his
username and password through the login form,
if so, checks authenticity in database and
creates session.
/
if(isset($POST['sublogin'])){
//include("main_page.php");
/ Check that all fields were typed in */
if(!$POST['user'] || !$_POST['pass']){
$msg = 'You didn\'t fill in a required field.';
displayLogin($msg);
die('');
}
/ Spruce up username, check length /
$POST['user'] = trim($POST['user']);
if(strlen($_POST['user']) > 30){
$msg = 'Sorry, the number is longer than 30 characters, please shorten it.';
displayLogin($msg);
die('');
}
/ Checks that username is in database and password is correct /
$md5pass = md5($POST['pass']);
$result = confirmUser($POST['user'], $md5pass);
/ Check error codes /
if($result == 1){
$msg = 'That number doesn\'t exist in our database.';
displayLogin($msg);
die('');
}
else if($result == 2){
$msg = 'Incorrect password.';
displayLogin($msg);
die('');
}
/ Username and password correct, register session variables /
$POST['user'] = stripslashes($POST['user']);
session_start();
$SESSION['userno'] = $POST['user'];
$SESSION['password'] = $md5pass;
setcookie("cookname2", $POST['user'],time()+3600);
setcookie("cookpass2", $md5pass, time()+3600);
$addr = "http://localhost/Login1/main.php";
$ipaddress = $SERVER['REMOTE_ADDR'];
$datetime = date("dⓂy G:i:s");
$comma_separated = 'Last Login';
$userno = $SESSION['userno'];
// Create log line
//$logline = '['. $datetime . '] [' . $ipaddress . '-' . $remotehost . '] [' . $username .'] ['. $page . "]";
$logline = "$datetime | $ipaddress | $userno| $comma_separated | $addr \n";
// Write to log file:
$logfile = '\htdocs\gft\log\logfile.txt';
// Open the log file in "Append" mode
if (!$handle = fopen($logfile, 'a+')) {
die("Failed to open log file");
}
// Write $logline to our logfile.
if (fwrite($handle, $logline) === FALSE) {
die("Failed to write to log file");
}
fclose($handle);
/**
This is the cool part: the user has requested that we remember that
he's logged in, so we set two cookies. One to hold his username,
and one to hold his md5 encrypted password. We set them both to
expire in 100 days. Now, next time he comes to our site, we will
log him in automatically.
/
if(isset($_POST['remember'])){
setcookie("cookname", $_SESSION['userno'], time()+60*60*24*100, "/");
setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/");
}
/ Quick self-redirect to avoid resending data on refresh /
echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
return;
}
/this is when user register for the first time/
if (isset($_POST['registersubmit'])){
global $conn;
$q = "SELECT userno FROM user WHERE userno = '$registerpassword'";
$result = mysql_query($q,$conn);
if(!$_POST['registerpassword']){
$msg = 'Please enter your mobile number';
displayLogin($msg);
die(''); //Indicates username failure
}
if(!$result ){
$msg ='No Mobile Number Found.';
displayLogin($msg);
die(''); //Indicates username failure
}
else if (mysql_numrows($result) >= 0){
$date = date("YmdHis");
$q = "INSERT INTO registerpassword VALUES('$registerpassword','$date')";
mysql_query($q,$conn);
$msg = 'Your new password will be sent to your mobile phone';
displayLogin($msg);
die ("");
}
}
/ Sets the value of the logged_in variable, which can be used in your code /
$logged_in = checkLogin();
?>
</BODY>
</HTML>