NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page [php] captcha not working (new)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Reply
 
LinkBack Thread Tools
Old 06-28-2009, 04:49 AM THREAD STARTER               #1 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




[php] captcha not working (new)


Hi all been doing my own captcha system and it seems to not want to work and i cannot figure out why.
Here is my captcha class:
PHP Code:
class captcha_pxb
{
    function 
generateRandom($length=6)
    {
        
// first array = digits, second = lowercase, third uppercase
        
$_rand_src = array(
        array(
48,57),
        array(
97,122),
        array(
65,90)
         );
         
        
$random_string "";
        for(
$i=0;$i<$length;$i++)
        {
            
$i1=rand(0,sizeof($_rand_src)-1);
            
$random_string .= chr(rand($_rand_src[$i1][0],$_rand_src[$i1][1]));
        }
        return 
$random_string;
    }
     
    function 
make_session()
    {
        
$_SESSION['captcha'] = $this->generateRandom(3);
        
$_SESSION['captcha_tmp'] = $this->generateRandom(3);  
    }
    
    
// check the wanted string against the one entered
    
function validate($wanted$entered)
    {
        if (
$wanted != $entered)
????: NamePros.com http://www.namepros.com/programming/592964-php-captcha-not-working-new.html
        {
            return 
false;
        }
        else
        {
            return 
true;
        }
    }

The image file:

PHP Code:
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0"false);
header("Pragma: no-cache");

// lets make the captcha image from the blank image
$im imagecreatefromjpeg("../../images/captcha_pxb.jpg");

// get the random strings from the session
$rand1 $_SESSION['captcha'];
$rand2 $_SESSION['captcha_tmp'];

ImageString($im522$rand1[0]." ".$rand1[1]." ".$rand1[2]." "ImageColorAllocate($im000));
????: NamePros.com http://www.namepros.com/showthread.php?t=592964
ImageString($im522" ".$rand2[0]." ".$rand2[1]." ".$rand2[2], ImageColorAllocate($im25500));
         
Header('Content-type: image/jpeg');
imagejpeg($imNULL100);
ImageDestroy($im); 
How i show it (this of course is not the whole file and yes i do start the session):
PHP Code:
require_once(PXB_ROOT '/includes/captchas/captcha_pxb.php');
     
$captcha = new captcha_pxb();
$captcha->make_session();

$guest_captcha = eval($templating->load('register''captcha_pxb')); 
It is as if the image file doesn't pick up the session, i tried including the file with most things commented about bar echoing $rand1 and 2 and it shows the correct two strings, but it won't show on the image, the image is just my blank image with no letters/numbers . It can't be my templating functions can it since sessions are a global?
Last edited by liam_d; 06-28-2009 at 08:33 AM.
liam_d is offline   Reply With Quote
Old 06-28-2009, 05:13 AM   #2 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
session_start();

Has to be called in the file you're including the captcha image in as well.

---------- Post added at 07:13 AM ---------- Previous post was at 07:12 AM ----------

So, try:

PHP Code:
session_start();

require_once(
PXB_ROOT '/includes/captchas/captcha_pxb.php');
????: NamePros.com http://www.namepros.com/showthread.php?t=592964

$captcha = new captcha_pxb();
$captcha->make_session();

$guest_captcha = eval($templating->load('register''captcha_pxb')); 
Eric is offline   Reply With Quote
Old 06-28-2009, 05:28 AM THREAD STARTER               #3 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Yes I know that, that is only a small snippet I start the session of course.

Like I said I've tried simply including the image generating file and having it simply echo the rand strings and they show but they won't show up on the image when I show the file like I showed.
liam_d is offline   Reply With Quote
Old 06-28-2009, 06:12 AM   #4 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
http://www.secondversion.com/Untitled.php

Testing there, it works. Are you sure you've specified the correct path to the image specified in imagecreatefromjpeg() ? Also, what happens if you visit the image file directly? (if in the web root)
Eric is offline   Reply With Quote
Old 06-28-2009, 06:22 AM THREAD STARTER               #5 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




That's the thing the image shows up fine but the letters\numbers dont. I tried adding in hardcoded letters to see if the imagestrings are working and they showed up fine, so somehow the image file cannot grab the session strings when displayed using the template system.

Going to the page itself will come up blank obviously as it won't have any information to use from the script that grabs it.
liam_d is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
My domain aint working... mebreezy Domain Name Discussion 12 05-09-2006 10:17 AM
Is Your Website Working Properly? - this software will make it sure c/w resale rights weblord For Sale / Advertising Board 0 05-07-2006 06:23 PM
MSN.com stop working for 4 ......... NamingJournal.com Industry News 10 05-01-2006 09:30 AM
IR generated mouseover JS code not working Ringr Programming 1 01-16-2006 05:58 AM
Forms stopped working...help! stu10 Programming 2 04-12-2005 01:49 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:30 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger