Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
can't generate CAPTCHA images on friends host
Old 04-26-2011, 05:34 AM can't generate CAPTCHA images on friends host
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I have a working CAPTCHA script that I'm using myself on my website. I gave a copy to my friend for his website but for some reason it doesn't work on his shared host. I've turned on all error reporting but I get nothing at all, just a blank page when I open the file.

The only thing left I can think of is that my friends host's php installation doesn't include the GB library. But then again, that should give some error of calling functions that doesn't exist. Can anybody think of another reason it wouldn't work?

I'll include the code, if you feel it would help to look at it.
PHP Code:
<?php
error_reporting
(E_ALL E_STRICT);
session_cache_expire(15);
session_start();

/*
* Modified by Mattias N. (2011-02-02)
* Information from original script is below.
*
* =====================================================================
*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php

* This program is free software; you can redistribute it and/or 
* modify it under the terms of the GNU General Public License 
* as published by the Free Software Foundation; either version 2 
* of the License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
* GNU General Public License for more details: 
* http://www.gnu.org/licenses/gpl.html
*
*/

class CaptchaSecurityImage {

    
// Some minor configurations
    
var $font 'TravelingTypewriter.ttf';    // Font to use in image
    
var $session_name 'security_code';    // Name of the session where code
                                            // is stored. Accessed through
                                            // $_SESSION[$session_name]
    
var $width 200;
    var 
$height 50;
    var 
$length 4;

    function 
generateCode($length) {
        
/* list all possible characters, similar looking characters and lowercase characters have been removed */
        
$allowed '23456789ABCDEFGHJKLMNPQRSTWXZ'
        
$code '';
        for (
$i 0$i $length$i++) { 
            
$code .= substr($allowedmt_rand(0strlen($allowed)-1), 1);
        }
        return 
$code;
    }
    
    function 
random_color($image$min 0$max 255) {
        return 
imagecolorallocate($imagemt_rand($min,$max), mt_rand($min,$max), mt_rand($min,$max));
    }
    
    function 
show() {
        
// If there is a previous code, reset it
        
$code $this->generateCode($this->length);
        
        
// font size will be 75% of the image height
        
$font_size $this->height 0.75;
        
        
// create new empty image
        
$image = @imagecreate($this->width$this->height) or die('Cannot Initialize new GD image stream');
        
        
// set some colors
        
$background_color $this->random_color($image090);
        
// $text_color = imagecolorallocate($image, 50, 50, 50);
        
$noise_color imagecolorallocate($image255255255); // White

        // generate random dots in background
        
for ($i 0$i < ($this->width*$this->height)/100$i++) {
            
imagefilledellipse($image,
                               
mt_rand(0,$this->width),        // x coordinate
                               
mt_rand(0,$this->height),    // y coordinate
                               
mt_rand(1,5),                // width
                               
mt_rand(1,5),                // height
                               
$noise_color                    // color
            
);
        }
        
/* generate random lines in background */
        // for( $i=0; $i<($width*$height)/500; $i++ ) {
        //     imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
        // }

        
$x_step $this->width 4;
        for (
$i=0$i strlen($code); $i++) {
            
$letter $code{$i};
            
$angle mt_rand(-3030);
            
$letterbox imagettfbbox($font_size$angle$this->font$letter);
            
$x $i $x_step + ($this->width $letterbox[4]) / 2;
            
$y = ($this->height 0.6 $letterbox[5]) / $this->height 0.2;
            
imagettftext($image$font_size$angle$x$y$this->random_color($image120255), $this->font$letter);
        }

        
// output image to browser
        
header('Content-Type: image/jpeg');
        
imagejpeg($image);
        
        
// destroy image
        
imagedestroy($image);
        
        
// set session variable
        
$_SESSION[$this->session_name] = $code;
    }

}

$captcha = new CaptchaSecurityImage();
$captcha->show();

?>
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 04-26-2011 at 05:37 AM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
 
Register now for full access!
Old 04-26-2011, 07:36 AM Re: can't generate CAPTCHA images on friends host
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
GD, not GB. Check with phpinfo call for starters. Can you see server error log?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 04-27-2011, 05:05 AM Re: can't generate CAPTCHA images on friends host
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I asked my friend for a phpinfo print out and the error logs yesterday when I saw your reply, but I havn't gotten his awnser yet. I'll get back here when I do.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 04-29-2011, 12:16 PM Re: can't generate CAPTCHA images on friends host
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Sigh, my friend didn't want any hassle.
He's just gonna skip using the CAPTCHA. Thanks for trying, though.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 05-20-2011, 08:08 AM Re: can't generate CAPTCHA images on friends host
Banned

Posts: 122
Name: devashish kumar
Trades: 0
No i cant do it,I try the above code but it don't work.
devashishseo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to can't generate CAPTCHA images on friends host
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.48242 seconds with 12 queries