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> PHP: //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); ?> PHP:
When you go to http://fatihonur.x10hosting.com/library/randomImage.php There is an error, therefore you don't get your image. [B]Fatal error[/B]: Call to undefined function imagecreate() in [B]/home/faonur/public_html/library/randomImage.php[/B] on line [B]11[/B] Code (markup): It seems your hosting does not support GD.
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?
GD Library is an addon to php which adds image edit / create functions.. ask your host to install or enable it
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: