PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Nov 22, 2014 3:32 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Sat Jan 22, 2011 8:01 am 
Offline
Forum Contributor
User avatar

Joined: Mon Dec 27, 2010 8:58 am
Posts: 134
I've written a captcha code for validation.
And I'm creating image with sending headers. So my image is being created but I can't display other part of page. I know it's obvious when sending headers first.

So I used an IFRAME that is having only code for displaying image.

So my login page having something like this ---

Syntax: [ Download ] [ Hide ]
<!--- other part of code goes here like my Form ! -->

<iframe src='captcha.php' name='captcha' width='250' height='100'>

<p> Can't see image ? <a href='captcha.php' target='captcha'> Get Another </a> </p>

<!--- other part of code goes here like my Form ! -->



It works fine in IE but not in FireFox and Safari.
Instead, in iframe it's showing some warning and garbage strings when page opened in FireFox and Safari.

I used DOCTYPE that allows frameset like this ----

Syntax: [ Download ] [ Hide ]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
 


Am I clear? It's confusing. Help. Thank you !


Top
 Profile  
 
PostPosted: Sat Jan 22, 2011 10:17 am 
Offline
Forum Commoner

Joined: Fri Jan 21, 2011 2:40 pm
Posts: 55
Location: Reston, VA
Did you close the iframe tag?


Top
 Profile  
 
PostPosted: Sat Jan 22, 2011 12:17 pm 
Offline
Forum Contributor
User avatar

Joined: Mon Dec 27, 2010 8:58 am
Posts: 134
I did. Here's the remaining code.

Syntax: [ Download ] [ Hide ]
<body>
<center>
<div class=postForm>
<form action="http://localhost/l/login_check.php" method="post">
<table border=1>
<tr>
        <td align=left width=250px><label><B><u>Login Form</u></b></label>
        <td align=left width=250px>&nbsp;<? if($loginfailed==1)
                {
                        echo('<font color=orange face=tahoma size=2> Wrong username or password !</font>');
                }      
               
        ?>
<tr>
        <td align=right width=250px><label>Username:</label>
        <td width=250px align=left><input type="text" name="uname" size="25">
<tr>
        <td align=right width=250px><label>Password:</label>
        <td width=250px align=left><input type="password" name="pword" size="25">
    <input type=hidden value="<?=$attempt?>" name=attempt>

<?

if($attempt>3)
{
?>
<tr>
        <td align=right width=250px><label>Enter Text from box:</label>
        <td align=left width=250px><input type=text name="captcha" size=25>

<tr>
        <td width=250px>&nbsp;</td>
        <td width=250px width=250px><iframe  class=iframe src="captcha.php" width=240px height=100px frameborder=0 marginheight=0 scrolling=no name=captcha></iframe>
<tr>
        <td width=250px>&nbsp;
        <td align=left width=250px><font color=white face=tahoma size=2>Can't see the text ? </font><a href="captcha.php" target="captcha">Get Another</a>
<tr>
        <td width=250px>&nbsp;</td>
        <td align=left width=250px><input type="submit" value="Login"></td>    
<?}
else
{?>
<tr>
        <td width=250px>&nbsp;</td>
        <td width=250px height=30px align=left><input type="submit" value="Login">
<?}
?>     

</form>
</div>
</center>
</body>


 


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 11:35 am 
Offline
Forum Commoner

Joined: Fri Jan 21, 2011 2:40 pm
Posts: 55
Location: Reston, VA
A few things I've noticed:

1) Your td tags aren't closed. Probably not the issue but it always helps to clean up html when you run into this kind of issue.

2) I tried your code and the iframe did work for me in Safari and FF. I don't have the captcha.php so I get a "file not found" message where the iframe is.

This tells me that the iframe IS working. It seems the output of captcha.php is the problem.

If you'd like to post that code I'd be happy to help.

I suspect you're creating a jpg and outputting it without telling the browser what kind of mime type it is. If so you'll need to send a header before you begin the output.


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 12:26 pm 
Offline
Forum Contributor
User avatar

Joined: Mon Dec 27, 2010 8:58 am
Posts: 134
gooney0 wrote:
A few things I've noticed:

1) Your td tags aren't closed. Probably not the issue but it always helps to clean up html when you run into this kind of issue.

2) I tried your code and the iframe did work for me in Safari and FF. I don't have the captcha.php so I get a "file not found" message where the iframe is.

This tells me that the iframe IS working. It seems the output of captcha.php is the problem.

If you'd like to post that code I'd be happy to help.

I suspect you're creating a jpg and outputting it without telling the browser what kind of mime type it is. If so you'll need to send a header before you begin the output.



ohh thank you very much.
it worked. I forgot to mention mime type. So I mentioned it in second line after starting session.

below is the code for capcha. Im creating new image from exising image existing image is just used as background for capcha text.
Syntax: [ Download ] [ Hide ]
<?
session_start();
header("Content-type: image/jpeg");
class captcha{
function create(){
$image=imagecreatefromjpeg("pic.jpg");
$col=imagecolorallocate($image, 0, 0,0);
$y=60;
$x=50;
$textColor[0] = imagecolorallocate($image, 0, 0, 0);
function GetRandChar($rN ) //randomize a char
{
$rT = $rN;//rand(0, $rN);
if($rT==0){
$rC = rand(48, 57);
}
elseif($rT==1){
$rC = rand(97, 122);
}
else{
$rC = rand(65, 90);
}
return chr($rC);
}

while($i<7){
$xy=rand(0,2);//to generate no bet 0 to 2. to select no,loweracse or upperacase chars.
$bC = GetRandChar($xy);
imagettftext($image, 40,0, $x, $y, $textColor[0], 'VREDROCK.ttf', $bC); //write down the  char
$capText.=$bC;
$i=$i+1;
$x=$x+20;
}
$_SESSION['capText']=md5(strtolower(trim($capText)));
imagejpeg($image); //show the image
imagedestroy($image);  //destroy it
}
}
$c=new captcha();
$c->create();
?>
 


also tell me is it good way of creating captcha? if not, why so?
thank you again.


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 12:35 pm 
Offline
Site Admin
User avatar

Joined: Tue Dec 23, 2003 3:10 am
Posts: 11470
Location: Toronto
Why are you using an iframe? Simply use an image tag..

<img src="catpcha.php" ...>


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 12:54 pm 
Offline
Forum Contributor
User avatar

Joined: Mon Dec 27, 2010 8:58 am
Posts: 134
John Cartwright wrote:
Why are you using an iframe? Simply use an image tag..

<img src="catpcha.php" ...>


that worked fine. thankyou. im using session to store and foword capcha text. and also im using session_start() when login page is opened. so both sessions might overlapped ! as im counting no of guests session is started on login page. will it create any problem???


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 12:56 pm 
Offline
Site Admin
User avatar

Joined: Tue Dec 23, 2003 3:10 am
Posts: 11470
Location: Toronto
phazorRise wrote:
John Cartwright wrote:
Why are you using an iframe? Simply use an image tag..

<img src="catpcha.php" ...>


that worked fine. thankyou. im using session to store and foword capcha text. and also im using session_start() when login page is opened. so both sessions might overlapped ! as im counting no of guests session is started on login page. will it create any problem???


no


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 1:02 pm 
Offline
Forum Contributor
User avatar

Joined: Mon Dec 27, 2010 8:58 am
Posts: 134
John Cartwright wrote:
phazorRise wrote:
John Cartwright wrote:
Why are you using an iframe? Simply use an image tag..

<img src="catpcha.php" ...>


that worked fine. thankyou. im using session to store and foword capcha text. and also im using session_start() when login page is opened. so both sessions might overlapped ! as im counting no of guests session is started on login page. will it create any problem???


no


sorry but is my capcha code is good and reliable enough to be implemented online?


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 1:08 pm 
Offline
Site Admin
User avatar

Joined: Tue Dec 23, 2003 3:10 am
Posts: 11470
Location: Toronto
It depends. Do you want to make it extremely difficult for everyone? Or just stop most people?

Creating a bulletproof captcha is extremely difficult to do, as you do not want to make it ineligible for humans to read. As far as your approach goes, your captcha I would consider extremely weak.

A couple suggestions:

1) Randomize the font for each letter
2) Randomize the size of the font for each letter within a threshold
3) Foreground and background noise
4) Distortion of the letters (i.e., skew the proportion and angles)
5) Overlapping of characters
6) Overlapping of random symbols on letters (i.e., squiggly line across entire captcha)

The list goes on and on. Just take a look at other captcha implementations, especially the ones that have been broken (and research why they have been broken).


Top
 Profile  
 
PostPosted: Sun Jan 23, 2011 1:15 pm 
Offline
Forum Contributor
User avatar

Joined: Mon Dec 27, 2010 8:58 am
Posts: 134
John Cartwright wrote:
It depends. Do you want to make it extremely difficult for everyone? Or just stop most people?

Creating a bulletproof captcha is extremely difficult to do, as you do not want to make it ineligible for humans to read. As far as your approach goes, your captcha I would consider extremely weak.

A couple suggestions:

1) Randomize the font for each letter
2) Randomize the size of the font for each letter within a threshold
3) Foreground and background noise
4) Distortion of the letters (i.e., skew the proportion and angles)
5) Overlapping of characters
6) Overlapping of random symbols on letters (i.e., squiggly line across entire captcha)

The list goes on and on. Just take a look at other captcha implementations, especially the ones that have been broken (and research why they have been broken).


Okay. I'll work on it. Looks like hard stuff but I'll try to make the best I can.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group