473,660 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Captchas and <img>

I have a captcha system going and for some reason when I use

<?php

$s = "";
for($i = 0; $i < 10; $i++) { $s = $s.rand(0,9); }
$_SESSION['CaptchaValue'] = $s;
$fn = '/Login/Register/Captcha.php';
echo '<img src="'.$fn.'" alt="Captcha" />';
?>

and Captcha.php uses require_once or include to include some classes that I
use to generate the captcha then it fails(usually get alt showed). But when
I include the classes directly inside the file it works ;/

This is very strange behavior? It really shouldn't matter if I do that,
right? And it is also a security issue because then if they can read the php
I they can get how I generate them.

What I can I do?

captcha.php

<?php

// Captcha classes inserted here but removed for brevity

header("Content-type: image/png");
session_start() ;
$f = $_SERVER['DOCUMENT_ROOT'].'/Login/Register/';
//require_once($f .'Captcha.php') ;

$c = new Captcha();

$c->Fonts->Add($f."1.TTF" , 0.23, 15, 2, 5, 0, 10, 20);
$c->Fonts->Add($f."2.TTF" , 0.5, 15, 2, 5, 0, 10, 20);
$c->Fonts->Add($f."3.TTF" , 0.27, 18, 2, 5, 0, 10, 20);
$c->Fonts->Add($f."4.TTF" , 0.27, 18, 2, 5, 0, 10, 20);

$s = $_SESSION['CaptchaValue'];
$img = $c->Create($s);

imagepng($img);
imagedestroy($i mg);

?>

Now I know the require is working or atleast when I debug I can step through
the classes so I'm sure its including it but it acts almost as if I'm not
including it(except I don't get any errors about it).

What ends up happening is either I get the alt showed or I get something
where its like the image is missing(but you get the border for with the X
icon).

Any ideas?

Thanks,
Jon
Jun 8 '07 #1
4 2006
On 8 Jun., 23:57, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
I have a captcha system going and for some reason when I use

<?php

$s = "";
for($i = 0; $i < 10; $i++) { $s = $s.rand(0,9); }
$_SESSION['CaptchaValue'] = $s;
$fn = '/Login/Register/Captcha.php';
echo '<img src="'.$fn.'" alt="Captcha" />';
?>

and Captcha.php uses require_once or include to include some classes that I
use to generate the captcha then it fails(usually get alt showed). But when
I include the classes directly inside the file it works ;/
Needed classes or other files must be included inside Catpcha.php.
First, the client will get an output including 10 html image tags.
After then, the client sends new requests, to get and display the
images. Therefore you must include them inside Captcha.php
This is very strange behavior? It really shouldn't matter if I do that,
right? And it is also a security issue because then if they can read the php
I they can get how I generate them.
Normally it's not possible to "read" PHP files. PHP code will
outputted by the Webserver if you use show_code() or if the Webserver
doesn't know what to to with files having .php format.
An approved way is to source out included files like classes, helper,
etc. outside the web directory. Then, nobody can require these files
directy by using a request.
What I can I do?

captcha.php

<?php

// Captcha classes inserted here but removed for brevity

header("Content-type: image/png");
session_start() ;

$f = $_SERVER['DOCUMENT_ROOT'].'/Login/Register/';
//require_once($f .'Captcha.php') ;

$c = new Captcha();

$c->Fonts->Add($f."1.TTF" , 0.23, 15, 2, 5, 0, 10, 20);
$c->Fonts->Add($f."2.TTF" , 0.5, 15, 2, 5, 0, 10, 20);
$c->Fonts->Add($f."3.TTF" , 0.27, 18, 2, 5, 0, 10, 20);
$c->Fonts->Add($f."4.TTF" , 0.27, 18, 2, 5, 0, 10, 20);

$s = $_SESSION['CaptchaValue'];
$img = $c->Create($s);

imagepng($img);
imagedestroy($i mg);

?>

Now I know the require is working or atleast when I debug I can step through
the classes so I'm sure its including it but it acts almost as if I'm not
including it(except I don't get any errors about it).

What ends up happening is either I get the alt showed or I get something
where its like the image is missing(but you get the border for with the X
icon).

Any ideas?

Thanks,
Jon

purcaholic

Jun 9 '07 #2

"purcaholic " <pu********@goo glemail.comwrot e in message
news:11******** **************@ p77g2000hsh.goo glegroups.com.. .
On 8 Jun., 23:57, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
>I have a captcha system going and for some reason when I use

<?php

$s = "";
for($i = 0; $i < 10; $i++) { $s = $s.rand(0,9); }
$_SESSION['CaptchaValue'] = $s;
$fn = '/Login/Register/Captcha.php';
echo '<img src="'.$fn.'" alt="Captcha" />';
?>

and Captcha.php uses require_once or include to include some classes that
I
use to generate the captcha then it fails(usually get alt showed). But
when
I include the classes directly inside the file it works ;/
Needed classes or other files must be included inside Catpcha.php.
First, the client will get an output including 10 html image tags.
After then, the client sends new requests, to get and display the
images. Therefore you must include them inside Captcha.php
huh? But require/include should do this? I shouldn't have to manually copy
the classes into the php directly but should be able to use require/include
in any php to include data? The client has nothing to do with this as it
doesn't see php.
>This is very strange behavior? It really shouldn't matter if I do that,
right? And it is also a security issue because then if they can read the
php
I they can get how I generate them.
Normally it's not possible to "read" PHP files. PHP code will
outputted by the Webserver if you use show_code() or if the Webserver
doesn't know what to to with files having .php format.
An approved way is to source out included files like classes, helper,
etc. outside the web directory. Then, nobody can require these files
directy by using a request.
Yes, but what I'm worrieda bout is security. Same reason not to include
password in php files. But as you said... an "approved way" is to source out
include files... yet I cannot do this because when I use require_once it
then doesn't work..

I don't think you fully understand the issue.

Say I have the captcha.php used for the image
//------------------- CASE 1

// class.php
<?php
class CaptchaMods()
{
function modifyimage($im g)
{
//.........
}
}
?>

// some php file
<?php

header("content-type: image/png");

//*************** **
require_once('c lass.php);

$c = new CaptchaMods();
$img = imagecreate(100 ,100);
$img = $c->modifyimage($i mg);
imagepng($img);
imagedestroy($i mg);
?>php

The above doesn't work, but this does
//------------------- CASE 2

// some php file
<?php

header("content-type: image/png");

//*************** **
class CaptchaMods()
{
function modifyimage($im g)
{
//.........
}
}

$c = new CaptchaMods();
$img = imagecreate(100 ,100);
$img = $c->modifyimage($i mg);
imagepng($img);
imagedestroy($i mg);
?>php
--------------

In CASE 2 all I did was copy and paste the class where the require was...
and now it works(well, this is just test code that might not work but is the
idea). This is essentially what require is suppose to do anyways? Only thing
I can think of is that require isn't working but when debugging I was able
to step through the class. Maybe for some reason its not so I'll have to
play around with it to see.
Thanks,
Jon
Jun 9 '07 #3
On 9 Jun., 14:12, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
"purcaholic " <purcaho...@goo glemail.comwrot e in message

news:11******** **************@ p77g2000hsh.goo glegroups.com.. .


On 8 Jun., 23:57, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
I have a captcha system going and for some reason when I use
<?php
$s = "";
for($i = 0; $i < 10; $i++) { $s = $s.rand(0,9); }
$_SESSION['CaptchaValue'] = $s;
$fn = '/Login/Register/Captcha.php';
echo '<img src="'.$fn.'" alt="Captcha" />';
?>
and Captcha.php uses require_once or include to include some classes that
I
use to generate the captcha then it fails(usually get alt showed). But
when
I include the classes directly inside the file it works ;/
Needed classes or other files must be included inside Catpcha.php.
First, the client will get an output including 10 html image tags.
After then, the client sends new requests, to get and display the
images. Therefore you must include them inside Captcha.php

huh? But require/include should do this? I shouldn't have to manually copy
the classes into the php directly but should be able to use require/include
in any php to include data? The client has nothing to do with this as it
doesn't see php.
This is very strange behavior? It really shouldn't matter if I do that,
right? And it is also a security issue because then if they can read the
php
I they can get how I generate them.
Normally it's not possible to "read" PHP files. PHP code will
outputted by the Webserver if you use show_code() or if the Webserver
doesn't know what to to with files having .php format.
An approved way is to source out included files like classes, helper,
etc. outside the web directory. Then, nobody can require these files
directy by using a request.

Yes, but what I'm worrieda bout is security. Same reason not to include
password in php files. But as you said... an "approved way" is to source out
include files... yet I cannot do this because when I use require_once it
then doesn't work..

I don't think you fully understand the issue.

Say I have the captcha.php used for the image

//------------------- CASE 1

// class.php
<?php
class CaptchaMods()
{
function modifyimage($im g)
{
//.........
}}

?>

// some php file
<?php

header("content-type: image/png");

//*************** **
require_once('c lass.php);

$c = new CaptchaMods();
$img = imagecreate(100 ,100);
$img = $c->modifyimage($i mg);
imagepng($img);
imagedestroy($i mg);
?>php

The above doesn't work, but this does

//------------------- CASE 2

// some php file
<?php

header("content-type: image/png");

//*************** **
class CaptchaMods()
{
function modifyimage($im g)
{
//.........
}

}

$c = new CaptchaMods();
$img = imagecreate(100 ,100);
$img = $c->modifyimage($i mg);
imagepng($img);
imagedestroy($i mg);
?>php

--------------

In CASE 2 all I did was copy and paste the class where the require was...
and now it works(well, this is just test code that might not work but is the
idea). This is essentially what require is suppose to do anyways? Only thing
I can think of is that require isn't working but when debugging I was able
to step through the class. Maybe for some reason its not so I'll have to
play around with it to see.

Thanks,
Jon- Zitierten Text ausblenden -

- Zitierten Text anzeigen -
Either the include path, where youre class besides, isn't in php
include_path setting, or included file has an white space, which will
be also send to the client. Check your'e captcha class for white space
characters before "<?php" or after ">?".

You wrote, that you could step to the class while debugging, therefore
i suppose an additional send character after header("content-type:
image/png"); causes the issue.
purcaholic

Jun 9 '07 #4

"purcaholic " <pu********@goo glemail.comwrot e in message
news:11******** *************@p 47g2000hsd.goog legroups.com...
On 9 Jun., 14:12, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
>"purcaholic " <purcaho...@goo glemail.comwrot e in message

news:11******* *************** @p77g2000hsh.go oglegroups.com. ..


On 8 Jun., 23:57, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
I have a captcha system going and for some reason when I use
><?php
>$s = "";
for($i = 0; $i < 10; $i++) { $s = $s.rand(0,9); }
$_SESSION['CaptchaValue'] = $s;
$fn = '/Login/Register/Captcha.php';
echo '<img src="'.$fn.'" alt="Captcha" />';
?>
>and Captcha.php uses require_once or include to include some classes
that
I
use to generate the captcha then it fails(usually get alt showed).
But
when
I include the classes directly inside the file it works ;/
Needed classes or other files must be included inside Catpcha.php.
First, the client will get an output including 10 html image tags.
After then, the client sends new requests, to get and display the
images. Therefore you must include them inside Captcha.php

huh? But require/include should do this? I shouldn't have to manually
copy
the classes into the php directly but should be able to use
require/include
in any php to include data? The client has nothing to do with this as it
doesn't see php.
>This is very strange behavior? It really shouldn't matter if I do
that,
right? And it is also a security issue because then if they can read
the
php
I they can get how I generate them.
Normally it's not possible to "read" PHP files. PHP code will
outputted by the Webserver if you use show_code() or if the Webserver
doesn't know what to to with files having .php format.
An approved way is to source out included files like classes, helper,
etc. outside the web directory. Then, nobody can require these files
directy by using a request.

Yes, but what I'm worrieda bout is security. Same reason not to include
password in php files. But as you said... an "approved way" is to source
out
include files... yet I cannot do this because when I use require_once it
then doesn't work..

I don't think you fully understand the issue.

Say I have the captcha.php used for the image

//------------------- CASE 1

// class.php
<?php
class CaptchaMods()
{
function modifyimage($im g)
{
//.........
}}

?>

// some php file
<?php

header("conten t-type: image/png");

//*************** **
require_once(' class.php);

$c = new CaptchaMods();
$img = imagecreate(100 ,100);
$img = $c->modifyimage($i mg);
imagepng($img) ;
imagedestroy($ img);
?>php

The above doesn't work, but this does

//------------------- CASE 2

// some php file
<?php

header("conten t-type: image/png");

//*************** **
class CaptchaMods()
{
function modifyimage($im g)
{
//.........
}

}

$c = new CaptchaMods();
$img = imagecreate(100 ,100);
$img = $c->modifyimage($i mg);
imagepng($img) ;
imagedestroy($ img);
?>php

--------------

In CASE 2 all I did was copy and paste the class where the require was...
and now it works(well, this is just test code that might not work but is
the
idea). This is essentially what require is suppose to do anyways? Only
thing
I can think of is that require isn't working but when debugging I was
able
to step through the class. Maybe for some reason its not so I'll have to
play around with it to see.

Thanks,
Jon- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Either the include path, where youre class besides, isn't in php
include_path setting, or included file has an white space, which will
be also send to the client. Check your'e captcha class for white space
characters before "<?php" or after ">?".

You wrote, that you could step to the class while debugging, therefore
i suppose an additional send character after header("content-type:
image/png"); causes the issue.

Seems to be working now. I just copyed the file and removes the non class
code in one and the class code in the other and then added the require. You
might have been right about the extra spaces... maybe before or after the
php code. I didn't think about that but thats probably the case cause it was
saying the image was invalid(atleast in firefox) so chances are some spaces
were getting inserted.

Thanks,
Jon
Jun 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3091
by: Philipp Lenssen | last post by:
My friend has the following problem (background: we want to transform XML to XHTML via XSLT): "We copy XHTML fragments into an output by using the following template: <xsl:template match="*" mode="xhtml"> <xsl:element name="{local-name()}"> <xsl:copy-of select="@*"/> <xsl:apply-templates mode="xhtml"/> </xsl:element>
5
2843
by: MyndPhlyp | last post by:
I've been busting my head trying to figure this out for quite some time. With IE6 and NS7, no problems. I can simply code the HTML <img height="100%"> and be done with it. But NS4 and NS6 (and probably a couple of other IE and NS versions I can't get to right now) don't want to play nice unless I hard code the image height. (Yes, I'm one of those who insists on still coding for NS4.)
8
67457
by: KS | last post by:
Just to show some code to show the consept. <img id="date" onclick="javascript:show_calendar();" src="/PlexSysWeb/images/show-calendar.gif" width=20 height=18 border=0> What i want the javascript to do is change the onclick value of the <IMG> tag above, by calling the test function from the same webpage by onclick on a button.
15
122124
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width: 123px; height: 456px;" alt="">
3
5442
by: Henry Johnson | last post by:
Okay - I'm spinning my wheels on this one... can someone help me figure out how to programmatically populate a table cell as follows (from C# code-behind)? I've tried using a Literal control in the TableCell, a HyperLink control, and an Image, but I'm not getting the results I want. Here's the source of what I'm after (retrieved by viewing the source of a page I'm trying to emulate): <td><a...
10
3281
by: News | last post by:
I am trying to be able to manipulate the width and height of an <img> but do not seem to be able. "Yes", I know the JavaScript will "not" manip anything, which is ok. I simply do not know how to capture the width or height. Once I can do that I can manipulate them. Here is the HTML for the <img> <div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)"> <img src="images/FirePlace.jpg" width="480" height="640" id="fpImg" />
1
4606
by: Carl | last post by:
Hi all I have a javascript function that drags and drops an element (ie img) into a container (ie bordered div). The function works and returns the element and and container. My next step is to center the element in the container if the user is sloppy with positioning it. I can only test this on IE6 and IE5.5 and it fails. It positions the element too much right and low. Here is the function: function SnapToContainer(Container,El) {
4
9073
by: SammyBar | last post by:
Hi all, I wonder is it possible to upload the content of an <imgfield to a server. The content of the <imgwas downloaded from a web site different from the one it should be uploaded. The image file should not be saved locally before uploading. It should not be visible any <input type=file on the form. How can it be done? I'm working on a project where client javascript requests an image server to generate dynamic images. The client...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.