Page 1 of 1

IFRAME not working on FireFox and Safari.

Posted: Sat Jan 22, 2011 7:01 am
by phazorRise
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 ---

Code: Select all

<!--- 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 ----

Code: Select all


<!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 !

Re: IFRAME not working on FireFox and Safari.

Posted: Sat Jan 22, 2011 9:17 am
by gooney0
Did you close the iframe tag?

Re: IFRAME not working on FireFox and Safari.

Posted: Sat Jan 22, 2011 11:17 am
by phazorRise
I did. Here's the remaining code.

Code: Select all

<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>



Re: IFRAME not working on FireFox and Safari.

Posted: Sun Jan 23, 2011 10:35 am
by gooney0
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.

Re: IFRAME not working on FireFox and Safari.

Posted: Sun Jan 23, 2011 11:26 am
by phazorRise
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.

Code: Select all

<?
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.

Re: IFRAME not working on FireFox and Safari.

Posted: Sun Jan 23, 2011 11:35 am
by John Cartwright
Why are you using an iframe? Simply use an image tag..

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

Re: IFRAME not working on FireFox and Safari.

Posted: Sun Jan 23, 2011 11:54 am
by phazorRise
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???

Re: IFRAME not working on FireFox and Safari.

Posted: Sun Jan 23, 2011 11:56 am
by John Cartwright
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

Re: IFRAME not working on FireFox and Safari.

Posted: Sun Jan 23, 2011 12:02 pm
by phazorRise
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?

Re: IFRAME not working on FireFox and Safari.

Posted: Sun Jan 23, 2011 12:08 pm
by John Cartwright
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).

Re: IFRAME not working on FireFox and Safari.

Posted: Sun Jan 23, 2011 12:15 pm
by phazorRise
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.