faonur
Apr 28th 2008, 6:12 am
I have just finished my final year thesis on my laptop using wamp. Everything worked. But after I upload my web site, admin part didin't work. It doesnt show random generated images.
I have just learned php last month. Please could you help me?
Web site: http://fatihonur.x10hosting.com/admin_login.php
Codes are below.
//admin_login.php
<?php
// we must never forget to start the session
session_start();
print_r($_SESSION);
//$_SESSION['image_random_value'] = '';
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
// first check if the number submitted is correct
$number = $_POST['txtNumber'];
if (md5($number) == $_SESSION['image_random_value']) {
include 'library/config.php';
include 'library/opendb.php';
$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
// check if the user id and password combination exist in database
$sql = "SELECT admin_username
FROM admin
WHERE admin_username = '$userId' AND admin_password = '$password'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
//echo "yes correct user name";
// the user id and password match,
// set the session
$_SESSION['image_is_logged_in'] = true;
$_SESSION['admin_is_logged_in'] = true;
// remove the random value from session
$_SESSION['image_random_value'] = '';
// after login we move to the main page
header('Location: admin.php');
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
include 'library/closedb.php';
} else {
$errorMessage = 'Sorry, wrong number. Please try again';
}
}
?>
<html>
<head>
<title>Basic Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
<?php
}
?>
<div align="center"> <h2> Admin Login </h2> </div>
<form action="" method="post" name="frmLogin" id="frmLogin">
<table width="500" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text" id="txtUserId"></td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password" id="txtPassword"></td>
</tr>
<tr>
<td width="150">Enter Number</td>
<td><input name="txtNumber" type="text" id="txtNumber" value="">
<img src="library/randomImage.php"></td>
</tr>
<tr>
<td width="150"> </td>
<td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>
//randomImage.php
<?php
session_start();
// generate 5 digit random number
$rand = rand(10000, 99999);
// create the hash for the random number and put it in the session
$_SESSION['image_random_value'] = md5($rand);
// create the image
$image = imagecreate(60, 30);
// use white as the background image
$bgColor = imagecolorallocate ($image, 255, 255, 255);
// the text color is black
$textColor = imagecolorallocate ($image, 0, 0, 0);
// write the random number
imagestring ($image, 5, 5, 8, $rand, $textColor);
// send several headers to make sure the image is not cached
// taken directly from the PHP Manual
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
// send the content type header so the image is displayed properly
header('Content-type: image/jpeg');
// send the image to the browser
imagejpeg($image);
// destroy the image to free up the memory
imagedestroy($image);
?>
I have just learned php last month. Please could you help me?
Web site: http://fatihonur.x10hosting.com/admin_login.php
Codes are below.
//admin_login.php
<?php
// we must never forget to start the session
session_start();
print_r($_SESSION);
//$_SESSION['image_random_value'] = '';
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
// first check if the number submitted is correct
$number = $_POST['txtNumber'];
if (md5($number) == $_SESSION['image_random_value']) {
include 'library/config.php';
include 'library/opendb.php';
$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
// check if the user id and password combination exist in database
$sql = "SELECT admin_username
FROM admin
WHERE admin_username = '$userId' AND admin_password = '$password'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
//echo "yes correct user name";
// the user id and password match,
// set the session
$_SESSION['image_is_logged_in'] = true;
$_SESSION['admin_is_logged_in'] = true;
// remove the random value from session
$_SESSION['image_random_value'] = '';
// after login we move to the main page
header('Location: admin.php');
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
include 'library/closedb.php';
} else {
$errorMessage = 'Sorry, wrong number. Please try again';
}
}
?>
<html>
<head>
<title>Basic Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
<?php
}
?>
<div align="center"> <h2> Admin Login </h2> </div>
<form action="" method="post" name="frmLogin" id="frmLogin">
<table width="500" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text" id="txtUserId"></td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password" id="txtPassword"></td>
</tr>
<tr>
<td width="150">Enter Number</td>
<td><input name="txtNumber" type="text" id="txtNumber" value="">
<img src="library/randomImage.php"></td>
</tr>
<tr>
<td width="150"> </td>
<td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>
//randomImage.php
<?php
session_start();
// generate 5 digit random number
$rand = rand(10000, 99999);
// create the hash for the random number and put it in the session
$_SESSION['image_random_value'] = md5($rand);
// create the image
$image = imagecreate(60, 30);
// use white as the background image
$bgColor = imagecolorallocate ($image, 255, 255, 255);
// the text color is black
$textColor = imagecolorallocate ($image, 0, 0, 0);
// write the random number
imagestring ($image, 5, 5, 8, $rand, $textColor);
// send several headers to make sure the image is not cached
// taken directly from the PHP Manual
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
// send the content type header so the image is displayed properly
header('Content-type: image/jpeg');
// send the image to the browser
imagejpeg($image);
// destroy the image to free up the memory
imagedestroy($image);
?>