Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Problems using CaptchaSecurityImages since PN PHP upgrade
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: Problems using CaptchaSecurityImages since PN ...
- « Previous
-
- 1
- 2
- Next »
Re: Problems using CaptchaSecurityImages since PN PHP upgrade
05-04-2010 8:59 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi alanru
I got this on your second comment...
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers: session2.php
If you think this is a server error, please contact the webmaster.
Error 500
I got this on your second comment...
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers: session2.php
If you think this is a server error, please contact the webmaster.
Error 500
Re: Problems using CaptchaSecurityImages since PN PHP upgrade
05-04-2010 9:14 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi to both alanru and Gabe,
Here are my 3 instances of code
1. The call from the html file to the php security file
2. The php security file
3. the php Post and redirect file
I cannot see what's wrong
1.
******************************************************************************************************************************************************************************
<img src="http://ccgi.netman.plus.com/cgi-bin/CaptchaSecurityImages.php" /><br />
<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" value=""/><br />
<p><br>
<input type="submit" name="submit" id="submit" class="button" value="Send message" tabindex="6" />
******************************************************************************************************************************************************************************
2.
******************************************************************************************************************************************************************************
<?php
//session_id("sec");
//session_start();
session_id("sec");
ini_set('session.save_path', '/files/home3/netman/cgi-bin/SESSIONS');
class CaptchaSecurityImages {
var $font = 'arial.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
******************************************************************************************************************************************************************************
3.
*****************************************************************************************************************************************************************************
<?php
//session_save_path('/files/home3/netman/cgi-bin/SESSIONS/');
//session_id("sec");
session_id("sec");
ini_set('session.save_path', '/files/home3/netman/cgi-bin/SESSIONS');
session_start();
`chmod 700 $fn`;
if( isset($_POST['submit'])) {
// get_security_picture($_SESSION['random'])
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'You have a message from Netmans Website';
// Your email address. This is where the form information will be sent.
$emailadd = 'web@netman.plus.com';
$emailaddfrom = 'Netman web feedback form';
// Where to redirect after form is processed.
$url = 'http://www.netman.plus.com/thankyou.html';
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------
$text = "Message from Netman Web email/feedback form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 100)
{echo "Name of form element $key cannot be longer than 100 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailaddfrom.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
unset($_SESSION['code']);
} else {
// Insert your code for showing an error message here
//echo "Sorry, you have provided an invalid security code";
header('Location:http://www.netman.plus.com/whoops.html');
}
} else {
}
?>
*******************************************************************************************************************************************
Thanks for all your help guys
Here are my 3 instances of code
1. The call from the html file to the php security file
2. The php security file
3. the php Post and redirect file
I cannot see what's wrong
1.
******************************************************************************************************************************************************************************
<img src="http://ccgi.netman.plus.com/cgi-bin/CaptchaSecurityImages.php" /><br />
<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" value=""/><br />
<p><br>
<input type="submit" name="submit" id="submit" class="button" value="Send message" tabindex="6" />
******************************************************************************************************************************************************************************
2.
******************************************************************************************************************************************************************************
<?php
//session_id("sec");
//session_start();
session_id("sec");
ini_set('session.save_path', '/files/home3/netman/cgi-bin/SESSIONS');
class CaptchaSecurityImages {
var $font = 'arial.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
******************************************************************************************************************************************************************************
3.
*****************************************************************************************************************************************************************************
<?php
//session_save_path('/files/home3/netman/cgi-bin/SESSIONS/');
//session_id("sec");
session_id("sec");
ini_set('session.save_path', '/files/home3/netman/cgi-bin/SESSIONS');
session_start();
`chmod 700 $fn`;
if( isset($_POST['submit'])) {
// get_security_picture($_SESSION['random'])
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'You have a message from Netmans Website';
// Your email address. This is where the form information will be sent.
$emailadd = 'web@netman.plus.com';
$emailaddfrom = 'Netman web feedback form';
// Where to redirect after form is processed.
$url = 'http://www.netman.plus.com/thankyou.html';
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------
$text = "Message from Netman Web email/feedback form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 100)
{echo "Name of form element $key cannot be longer than 100 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailaddfrom.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
unset($_SESSION['code']);
} else {
// Insert your code for showing an error message here
//echo "Sorry, you have provided an invalid security code";
header('Location:http://www.netman.plus.com/whoops.html');
}
} else {
}
?>
*******************************************************************************************************************************************
Thanks for all your help guys
Re: Problems using CaptchaSecurityImages since PN PHP upgrade
05-04-2010 9:43 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi Alan,
Try
suitably edited for your path. Call it in a few browsers. Then look in /SESSION and count the sessions.
Gabe
Try
<?php
ini_set('session.save_path', '/files/homeX/username/SESSION');
session_id("test");
session_start();
?>
suitably edited for your path. Call it in a few browsers. Then look in /SESSION and count the sessions.
Gabe
Re: Problems using CaptchaSecurityImages since PN PHP upgrade
05-04-2010 9:49 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Do we have a happy ending?
Both my original scripts without any alterations are now working again - Plusnet have been busy.
Netman - have you tried your original scripts again?
Both my original scripts without any alterations are now working again - Plusnet have been busy.
Netman - have you tried your original scripts again?
Re: Problems using CaptchaSecurityImages since PN PHP upgrade
05-04-2010 9:51 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi Netman,
You appear to have taken the session_start(); out of your image generator.
try just
Gabe
You appear to have taken the session_start(); out of your image generator.
try just
ini_set('session.save_path', '/files/home3/netman/cgi-bin/SESSIONS');
session_start();
Gabe
Re: Problems using CaptchaSecurityImages since PN PHP upgrade
05-04-2010 10:28 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Apologies - please ignore call to confirm happy ending - seems I cleared the wrong browser cache!
But the main point still applies.
Call session_start(); on your local server & you will note a session id cookie set up with a lengthy
ref. The call fails on Plusnet's implementation.
The workaround is to specifically set a short session id to avoid PHP generating a long reference
which Plusnet cannot handle.
Any script calling session_start() on Plusnet is bound to fail - the captcha image routines which
most content management systems employ make use of this function & will fail to show any image.
But the main point still applies.
Call session_start(); on your local server & you will note a session id cookie set up with a lengthy
ref. The call fails on Plusnet's implementation.
The workaround is to specifically set a short session id to avoid PHP generating a long reference
which Plusnet cannot handle.
Any script calling session_start() on Plusnet is bound to fail - the captcha image routines which
most content management systems employ make use of this function & will fail to show any image.
Re: Problems using CaptchaSecurityImages since PN PHP upgrade
05-04-2010 10:56 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi Netman,
And the next problem is with the font. Try:
That should deliver a captcha.
Gabe
And the next problem is with the font. Try:
<?php
ini_set('session.save_path', '/files/home3/netman/cgi-bin/SESSIONS');
session_start();
class CaptchaSecurityImages {
var $font = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.6;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
That should deliver a captcha.
Gabe
Re: Problems using CaptchaSecurityImages since PN PHP upgrade
05-04-2010 11:34 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi Abie
Cc alanru
(well maybe not the last one)
So the font line var $font = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf';
was the cause of the problem
Thank you all very much for your time and paitence
Cc alanru
(well maybe not the last one)
So the font line var $font = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf';
was the cause of the problem
Thank you all very much for your time and paitence
Re: Problems using CaptchaSecurityImages since PN PHP upgrade
06-04-2010 8:58 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Yup, the problem with CaptchaSecurityImages was it couldn't find arial. If Plusnet don't pick up this thread you might want to drop them a line to request a few basic .ttf fonts for use with GD.
The problem with the security.lib.php script was that it didn't set the session variable so needed to be edited or run through a wrapper, like in #5.
The problem with session_id("test"); is that all your visitors end up in the same session. There's a reason for the long hash of numbers in a session id. So, if you haven't already, do remove that line.
Good luck.
Gabe
The problem with the security.lib.php script was that it didn't set the session variable so needed to be edited or run through a wrapper, like in #5.
The problem with session_id("test"); is that all your visitors end up in the same session. There's a reason for the long hash of numbers in a session id. So, if you haven't already, do remove that line.
Good luck.
Gabe
- « Previous
-
- 1
- 2
- Next »
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- Re: Problems using CaptchaSecurityImages since PN ...