cancel
Showing results for 
Search instead for 
Did you mean: 

Problems using CaptchaSecurityImages since PN PHP upgrade

netman
Grafter
Posts: 27
Registered: ‎10-08-2007

Problems using CaptchaSecurityImages since PN PHP upgrade

Huh Does anyone know how I can use CaptchaSecurityImages on my sumit forms as they were working before PN PHP upgrade and now they don't.
Where the page should display the security image I just get a red cross. Tried every trick that I know and now have run out of options.
Can anyone help please?
Netman
23 REPLIES 23
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

The image is showing. Have you flushed your browser cache?
Gabe
netman
Grafter
Posts: 27
Registered: ‎10-08-2007

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Undecided Hi Gabe
The image is not showing and I have used 2 different kind of browsers i.e. Chrome and IE. No matter what I do the images do not show. The image that you saw was a static image just to make sure that images were not blocked from PHP pages.
Netman
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Hi Netman,
What I saw was images generated by http://ccgi.netman.plus.com/cgi-bin/security.lib.php. I reloaded the page and got a new picture each time. I still do if I use that url directly, though I see it's now been removed from the page.
Gabe
netman
Grafter
Posts: 27
Registered: ‎10-08-2007

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Huh Hi Gabe
Yes you are right. I was a bit missleading. The image did reload but the PHP security.lib.php  page would not release the numbers and letters. The to the contact page. I therefore tried another PHP page CaptchaSecurityImages.php which I found on the web and it just leaves a red cross still not passing the numbers and letters back. I am not sure what is going on as I tested both pages on my local machine and they seem to work fine. Confused or what???  Crazy
Netman
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Hi Netman,
How are you passing the variable? I'd expect the security.lib.php script to work with something like:
<?php
session_start();
require_once "security.lib.php";
//Generate random code.
$_SESSION['random'] = generate_random_code(SP_KEY);
//Show picture
get_security_picture($_SESSION['random']);

?>

and then use $_SESSION['random'] in the script that receives your form. Or have I misunderstood the problem?
Gabe
netman
Grafter
Posts: 27
Registered: ‎10-08-2007

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

HI Gabe
Thanks for all your help but I am getting nowhere at the moment. It's a same that before PN upgraded to PHP5 all was well with my site but now I'm pulling my hair out. Well, I would if I had any  Cool
Anyway. The contact page is a html page as you know and it refers to the security.lib.php page
Code:
<?php

define('SP_KEY',        '234612ASgBY0985Sfvtr3WDA345w3f35345dfb');
define('SP_CODE_LENGTH','5');
define('SP_CODE_OFFSET','2');
define('SP_QUALITY',    '80');
define('SP_WIDTH',      '60');
define('SP_HEIGTH',    '30');
define('SP_CIRCLES',    '100');
define('SP_FONT',      '10');
define('SP_TEXT_X',    '7');
define('SP_TEXT_Y',    '7');
//generate random code. this code will be displayed at the image
//
function generate_random_code($key)
{
    return substr(md5($_SERVER['HTTP_USER_AGENT'] . $key . date("YmdHis")), SP_CODE_OFFSET, SP_CODE_LENGTH);
}
//generate picture
//
function get_security_picture($code) {
//set height and width for image font
//
    ImageFontWidth(SP_FONT);
    ImageFontHeight(SP_FONT);
//create image
//
    $im = @imagecreate(SP_WIDTH, SP_HEIGTH);
//set image color
//
    imagecolorallocate($im, 255 , 255, 255);
//set random text color
//
    $text_color = imagecolorallocate($im, rand(0,100), rand(0,100), rand(0,100));
//create random color circles
//
    for ($i=1; $i<=SP_CIRCLES; $i++) {
        $randomcolor = imagecolorallocate($im , rand(100,255), rand(100,255), rand(100,255));
        imagefilledellipse($im, rand(0, SP_WIDTH-10), rand(0, SP_HEIGTH-3), rand(20,70), rand(20,70), $randomcolor);
    }
    imagerectangle($im, 0, 0, SP_WIDTH-1, SP_HEIGTH-1, $text_color);
    imagestring($im, SP_FONT, SP_TEXT_X, SP_TEXT_Y, $code, $text_color);
//output image in browser
    header ("Content-type: image/jpeg");
    imagejpeg($im, '', SP_QUALITY);
//destroy current image
//
    ImageDestroy($im);
}
get_security_picture(generate_random_code(SP_KEY));
?>

This places an image ib the html page. Somehow I need to get the image contects to the text box called code and then this is posted to my sendmail php page
Code:
<?php
session_save_path('/files/home3/netman/cgi-bin/SESSIONS/');
session_start();
if( isset($_POST['submit'])) {
   
if( $_SESSION['code'] == $_POST['code'] && !empty($_SESSION['code'] ) ) {
  //if( $_SESSION['code'] == $_POST['code'] && !empty($_SESSION['code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
////echo 'Thank you. Your message said "'.$_POST['message'].'"';


//--------------------------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 {
}
?>
David_W
Rising Star
Posts: 2,305
Thanks: 32
Registered: ‎19-07-2007

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

This may have nothing to do with it, but if it's a direct paste you have several major typos in your code.......
define('SP_HEIGTH',     '30');

Shouldn't it be SP_HEIGHT?
netman
Grafter
Posts: 27
Registered: ‎10-08-2007

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Undecided
OK now you've got me...
define('SP_HEIGTH',    '30');
Shouldn't it be SP_HEIGHT?
Arn't they both the same or are my eyes fuzzy from being infornt of the screen too long  Crazy
Oldjim
Resting Legend
Posts: 38,460
Thanks: 741
Fixes: 63
Registered: ‎15-06-2007

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

spelling of height  Shocked
alanrm
Newbie
Posts: 4
Registered: ‎05-04-2010

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Come on Plusnet - this is a problem in PHP implementation & has exactly the same cause as the problems with sessions.
ALL calls to  session_start(); are failing - there is another post describing complicated ways of getting round it. I found a simpler way
which has also solved the problem with showing the captcha image.
If no session id is assigned php automatically assigns a reference when session_start is called BUT the length of this reference
is too long & choking Plusnet's php implementation. Nothing wrong with scripts, nothing wrong on my Win32 or Ubuntu Linux implementations
with PHP5 - it is Plusnet's implementation.
I use PHPFusion so I can't comment directly on your case but the captcha routine there includes a call to session_start();
The solution is to call session_id(); before calling session_start(); & assigning a short id
eg  session_id("sec"); 
This has worked both for IM scripts which use session_start(); & PHPFusions  new Member registration script which uses
captcha images.
So... look in your script for the call to session_start(); & place session_id("sec");  before it & voila!


netman
Grafter
Posts: 27
Registered: ‎10-08-2007

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Hi ananrm,
Thanks for the info. But alas I have put my website back to it's original state except for the PHP pages having
session_save_path('/files/home3/netman/cgi-bin/SESSIONS/');
session_id("sec"); 
session_start();
at the top and still no security images shows.... I must be going do-lally by now I guess.
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Quote from: netman
session_save_path('/files/home3/netman/cgi-bin/SESSIONS/');

Try
ini_set('session.save_path', '/files/home3/netman/cgi-bin/SESSIONS');

And remove session_id("sec");
Gabe
netman
Grafter
Posts: 27
Registered: ‎10-08-2007

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Hi Gabe
Thanks for the info.
I don't have an issue with the sessions it's the image security I have a problem with.
However I have done as stated and still no change. I am sure the issue lies with PN PHP config  Crazy
alanrm
Newbie
Posts: 4
Registered: ‎05-04-2010

Re: Problems using CaptchaSecurityImages since PN PHP upgrade

Hi netman,
Just to emphasize that it IS the session_start() function implementation which is causing the problem - you are viewing the captcha image
as something different but the problem is caused by the session_start function which is used in this script.
I came to  your query because I had problems with this function in an IM script & after reading your query I found that suddenly the captcha image was not appearing in my PN PHPFusion setup. It was therefore no surprise at all to find that the captcha script included a call to the very same function. These are now working again after my amendment.
I don't know why you need to specify a session save path - does your original script do this? The ONLY change I had to make to two different
scripts causing problems was to set a short file length id by calling session_id() before session_start() specifically to address the error
notice being generated by PHP.
Of course, a reference generated automatically by PHP for a session id should not be rejected by PHP & is not by any other implementation that I have come across.
To Gabe I would say-
Try uploading this script to PN & then explain how to solve the error. There should of course be no error message.
<?php
session_start();
?>
Now upload this:-
<?php
session_id("test");
session_start();
?>
You will of course get a white screen but look at your cookies - the PHPSESSIONID has been successfully created  - it failed on the call just to
session_start()