Loans - Car Loan - Web directory - Home Insurance - Loans

PDA

View Full Version : Why this code doesn't work online? IMPORTANT


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="">
&nbsp;&nbsp;<img src="library/randomImage.php"></td>
</tr>

<tr>
<td width="150">&nbsp;</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);
?>

xrvel
Apr 28th 2008, 7:08 am
When you go to
http://fatihonur.x10hosting.com/library/randomImage.php

There is an error, therefore you don't get your image.
Fatal error: Call to undefined function imagecreate() in /home/faonur/public_html/library/randomImage.php on line 11It seems your hosting does not support GD.

faonur
Apr 28th 2008, 9:48 am
Thank you very much for your quick response `xrvel`.
May I ask u that what what is GD or What further step I have to take to get rid of from this error?

Acecool
Apr 28th 2008, 10:19 am
GD Library is an addon to php which adds image edit / create functions.. ask your host to install or enable it :-)

faonur
Apr 29th 2008, 9:41 am
Thank you too Acecool.
This is the fastest form site I have ever seen. guys, you are very helpful.

phpl33t
Apr 29th 2008, 12:55 pm
imagecreate() is only for GD1 and for GD 2 use: imagecreatetruecolor()

If you have WHM, recomiled apache using easyapache and be sure to include GD. (All point and click).

If you still need help hit me up.

Also try this:

if (function_exists('imagecreatetruecolor')){
use imagecreatetruecolor()
}else{
use imagecreate()
}