Jump to content


Photo

Help Needed! Image Verification


  • Please log in to reply
6 replies to this topic

#1 bandit8

bandit8
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 09 September 2006 - 08:41 PM

Hi Everyone,
I am trying to get an image verification system working...I have been going through the tutorial at:
http://www.php-mysql...erification.php

But I keep getting the error:
Parse error: parse error, unexpected T_STRING in /homepages/41/d171489552/htdocs/image_verification/test.php on line 8

This is the code I have:
-----

<?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);
?>

----
It's copied right from the tutorial, so I don't get why it would be giving me an error!

Any thoughts/suggestions would be greatly appreciated.

Thanks

b.

#2 ahmed17

ahmed17
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 09 September 2006 - 09:07 PM

change the following code and it will work well
header('Content-type: image/gif');

and

imagegif($image);


#3 bandit8

bandit8
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 09 September 2006 - 09:29 PM

change the following code and it will work well

header('Content-type: image/gif');

and

imagegif($image);


Hi Ahmed,
That still gives me the exact same error... its pointing to line 8... I can't see what would be wrong with it..?

b.

#4 ahmed17

ahmed17
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 09 September 2006 - 09:51 PM

testing on a live web server off in a separate test folder  may be it will work well and i test code
and give me result
*gd in localhost give me also error


#5 bandit8

bandit8
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 09 September 2006 - 11:19 PM

testing on a live web server off in a separate test folder  may be it will work well and i test code
and give me result
*gd in localhost give me also error


I have it on a live server, in a separate folder for testing...

#6 jefkin

jefkin
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 10 September 2006 - 12:43 AM

Hi bandit,

I don't think this will solve your problem, but may help locate it specifically, as I count it, this is line 8 in your code:

$_SESSION['image_random_value'] = md5($rand); 

With that error, it seems to me that it's choking on the 'image_random_value'.

If I've counted right, then this is just a dummy test, but try putting new lines in the code like this:


$rand = $rand; // see if error might be from above then should give this line as error again.
$_SESSION[
'image_random_value'
] 
= 
md5(
$rand
); 

See if or how the line number changes, to pinpoint what is causing the problem.  Good Luck.

Jeff

#7 bandit8

bandit8
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 11 September 2006 - 04:48 PM

I figured out what the problem was...

I had copied a section of the tutorial code straight from the browser..and somehow it must have picked up an invisible character... for as soon as I retyped it all manually, it worked fine.

Thanks for all the suggestions and trying to help though!

-b.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users