IFRAME not working on FireFox and Safari.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

IFRAME not working on FireFox and Safari.

Postby phazorRise » Sat Jan 22, 2011 8:01 am

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 !
User avatar
phazorRise
Forum Contributor
 
Posts: 134
Joined: Mon Dec 27, 2010 8:58 am

Re: IFRAME not working on FireFox and Safari.

Postby gooney0 » Sat Jan 22, 2011 10:17 am

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

Re: IFRAME not working on FireFox and Safari.

Postby phazorRise » Sat Jan 22, 2011 12:17 pm

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>


 
User avatar
phazorRise
Forum Contributor
 
Posts: 134
Joined: Mon Dec 27, 2010 8:58 am

Re: IFRAME not working on FireFox and Safari.

Postby gooney0 » Sun Jan 23, 2011 11:35 am

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.
gooney0
Forum Commoner
 
Posts: 55
Joined: Fri Jan 21, 2011 2:40 pm
Location: Reston, VA

Re: IFRAME not working on FireFox and Safari.

Postby phazorRise » Sun Jan 23, 2011 12:26 pm

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.
User avatar
phazorRise
Forum Contributor
 
Posts: 134
Joined: Mon Dec 27, 2010 8:58 am

Re: IFRAME not working on FireFox and Safari.

Postby John Cartwright » Sun Jan 23, 2011 12:35 pm

Why are you using an iframe? Simply use an image tag..

<img src="catpcha.php" ...>
Code: Select all
if ($toBe || $notToBe) echo 'That is the question'; 

NEW HERE?: Please read the Forum Rules, and take the Forum Tour before posting!
User avatar
John Cartwright
Site Admin
 
Posts: 11470
Joined: Tue Dec 23, 2003 3:10 am
Location: Toronto

Re: IFRAME not working on FireFox and Safari.

Postby phazorRise » Sun Jan 23, 2011 12:54 pm

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???
User avatar
phazorRise
Forum Contributor
 
Posts: 134
Joined: Mon Dec 27, 2010 8:58 am

Re: IFRAME not working on FireFox and Safari.

Postby John Cartwright » Sun Jan 23, 2011 12:56 pm

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
Code: Select all
if ($toBe || $notToBe) echo 'That is the question'; 

NEW HERE?: Please read the Forum Rules, and take the Forum Tour before posting!
User avatar
John Cartwright
Site Admin
 
Posts: 11470
Joined: Tue Dec 23, 2003 3:10 am
Location: Toronto

Re: IFRAME not working on FireFox and Safari.

Postby phazorRise » Sun Jan 23, 2011 1:02 pm

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?
User avatar
phazorRise
Forum Contributor
 
Posts: 134
Joined: Mon Dec 27, 2010 8:58 am

Re: IFRAME not working on FireFox and Safari.

Postby John Cartwright » Sun Jan 23, 2011 1:08 pm

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).
Code: Select all
if ($toBe || $notToBe) echo 'That is the question'; 

NEW HERE?: Please read the Forum Rules, and take the Forum Tour before posting!
User avatar
John Cartwright
Site Admin
 
Posts: 11470
Joined: Tue Dec 23, 2003 3:10 am
Location: Toronto

Re: IFRAME not working on FireFox and Safari.

Postby phazorRise » Sun Jan 23, 2011 1:15 pm

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.
User avatar
phazorRise
Forum Contributor
 
Posts: 134
Joined: Mon Dec 27, 2010 8:58 am


Return to PHP - Code

Who is online

Users browsing this forum: Bing [Bot] and 9 guests