Jump to content

Archived

This topic is now archived and is closed to further replies.

bandit8

Help Needed! Image Verification

Recommended Posts

Hi Everyone,
I am trying to get an image verification system working...I have been going through the tutorial at:
http://www.php-mysql-tutorial.com/user-authentication/image-verification.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.

Share this post


Link to post
Share on other sites
change the following code and it will work well
[code]header('Content-type: image/gif');[/code]

and

[code]imagegif($image);[/code]

Share this post


Link to post
Share on other sites
[quote author=ahmed17 link=topic=107488.msg431346#msg431346 date=1157836059]
change the following code and it will work well
[code]header('Content-type: image/gif');[/code]

and

[code]imagegif($image);[/code]
[/quote]

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[quote author=ahmed17 link=topic=107488.msg431361#msg431361 date=1157838712]
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

[/quote]

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

Share this post


Link to post
Share on other sites
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:

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

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:


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

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

Jeff

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.