Jump to content

Recommended Posts

In the include at the start of the code session_start() is beign called.

 

Part of the script:

  if ($_POST['submit']) {
    echo 'C='.$_SESSION['vercode'].'<br />V='.md5($_POST['vcode']);
    if (md5($_POST['vcode'])==$_SESSION['vercode']) {

 

My captcha script:

<?php
  /* makeimg.php
  **
  ** Created: 11-Jun-2007 (Zeb)
  ** Edited : 11-Jun-2007 (Zeb)
  *****************************************************************************/
  session_start();
  $imgWidth=130;
  $imgHeight=34;
  $chars='abcdefghijkmnqrstuvwxyz0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';
  $strText='';
  for ($i=1;$i<7;$i++) {$strText.=substr($chars,mt_rand(0,strlen($chars)-1),1);}
  $_SESSION['vercode']=md5($strText);
  header("Content-type: image/png");
  $img=imagecreatetruecolor($imgWidth,$imgHeight); //22
  $colBG=imagecolorallocate($img,0x11,0x11,0x11);
  $colFG=imagecolorallocate($img,255,255,255);
  for ($i=0;$i<strlen($strText);$i++) {
    $colFG=imagecolorallocate($img,mt_rand(100,255),mt_rand(100,255),mt_rand(100,255));
    imagettftext($img,20,mt_rand(-40,40),10+($i*20),27,$colFG,'fonts/times.ttf',substr($strText,$i,1));
  }
  imagepng($img);
  imagedestroy($img);
?>

 

In the captcha script I've tried removing session_start() in case that makes a difference and it doesn't. I've also got two other sites hosted on exactly the same web space using the same code and they both work - this one doesn't.

 

I just can't get the session variable to read - this is a sample of what I get in the browser:

C=
V=3588b8a8010f88846007457cf3cb87fd

 

Anyone see what I'm doing wrong here?

 

btw, this is the page in action:

http://braeside.pictureinthesky.net/contactus.php

heh how true!

 

Here's what I used for testing:

<?php
  session_start;
  echo 'SESSION:<pre>',print_r($_SESSION),'</pre>';
  echo 'SESSIONcheese:<pre>',print_r($_SESSION['cheese']),'</pre>';
  $_SESSION['cheese']=md5('bleh');
  echo 'SESSIONcheese<pre>',print_r($_SESSION['cheese']),'</pre>';
?>

 

The result can be seen here: http://braeside.pictureinthesky.net/test.php

Here's the entire script:

<?php
  include("db_connect.php");
  include("fn_encodestr.php");
  include("fn_secureint.php");
  $fetch=mysql_fetch_array(mysql_query("SELECT * FROM years WHERE `yearid`='1'"));
  $yrmin=$fetch['min'];
  $yrmax=$fetch['max'];
  $message="";
  echo $_SESSION['vercode'];
  $months=array("X","January","February","March","April","May","June","July","August","September","October","November","December");
  $rooms=array("Single Standard","Double Standard","Double Ensuite","Twin Standard","Twin Ensuite","Family Room");
  $sendemail=false;
  $numadults=1;
  $gname=encodestr($_POST['name']);
  $gemail=encodestr($_POST['email']);
  $gphone=encodestr($_POST['phone']);
  $garrday=$_POST['arrday'];
  $garrmonth=$_POST['arrmonth'];
  $garryear=$_POST['arryear'];
  $gdepday=$_POST['depday'];
  $gdepmonth=$_POST['depmonth'];
  $gdepyear=$_POST['depyear'];
  $gnumnights=secureint($_POST['numnights']);
  $gnumadults=secureint($_POST['numadults']);
  $gnumchildren=secureint($_POST['numchildren']);
  $gquery=encodestr($_POST['query']);
  if ($_POST['submit']) {
    //echo 'C='.$_SESSION['vercode'].'<br />V='.md5($_POST['vcode']);
    //if (md5($_POST['vcode'])==$_SESSION['vercode']) {
      if ($_POST['name']) {
        if ($_POST['email']) {
          if ($gnumadults<1) {
            $message="At least one adult must accompany each booking";
            $numadults=1;
          } else {
            $groom1qty=$_POST['room1qty'];
            $groom1type=$_POST['room1type'];
            $groom2qty=$_POST['room2qty'];
            $groom2type=$_POST['room2type'];
            if ($_POST['query']) {
              mysql_query("INSERT INTO `emailqueries` (`name`,`email`,`phone`,`arrday`,`arrmonth`,`arryear`,`depday`,`depmonth`,`depyear`,`nights`,`adults`,`children`,`room1qty`,`room1type`,`room2qty`,`room2type`,`query`,`dt`) VALUES ($gname,$gemail,$gphone,$garrday,$garrmonth,$garryear,$gdepday,$gdepmonth,$gdepyear,$gnumnights,$gnumadults,$gnumchildren,$groom1qty,$groom1type,$groom2qty,$groom2type,$gquery,NOW() )");
              $message="Name: $gname\nEmail: $gemail\nPhone: $gphone\n\n";
              $message.="Arrival Date: $garrday ".$months[$garrmonth]." $garryear\n";
              $message.="Departure Date: $gdepday ".$months[$gdepmonth]." $gdepyear\n";
              $message.="Nights: ".$gnumnights."\n\n";
              $message.="Adults: ".$gnumadults."\n";
              $message.="Children: ".$gnumchildren."\n\n";
              $message.="Rooms:\n$groom1qty of ".$rooms[$groom1type]."\n";
              $message.="$groom2qty of ".$rooms[$groom2type]."\n\n";
              $message.=stripslashes($gquery);
              $headers="From: $gname <$gemail>\r\n";
              $subject="Online query";
              if (mail("braesidehotel@blueyonder.co.uk",$subject,$message,$headers)) {
                $message="Email sent";
              } else {
                $message="There was a problem sending the email - please try again later";
              }
              $sendemail=true;
            } else {$message="Please supply a comment/query";}
          }
        } else {$message="You need to enter a valid contact email address";}
      } else {$message="You need to enter a contact name";}
    //} else {$message="The verification code doesn't match";}
  }
  //KEEP THE VALUES OF ARRIVAL DATE
  $strarrday="";
  for ($i=1;$i<32;$i++) {
    $strarrday.="<option value=\"$i\"";
    if ($i==$garrday) {$strarrday.=" selected";}
    $strarrday.=">$i</option>";
  }
  $strarrmonth="";
  for ($i=1;$i<13;$i++) {
    $strarrmonth.="<option value=\"$i\"";
    if ($i==$garrmonth) {$strarrmonth.=" selected";}
    $strarrmonth.=">".$months[$i]."</option>";
  }
  $strarryear="";
  for ($i=$yrmin;$i<=$yrmax;$i++) {
    $strarryear.="<option value=\"$i\"";
    if ($i==$garryear) {$strarryear.=" selected";}
    $strarryear.=">$i</option>";
  }
  //KEEP THE VALUES OF DEPARTURE DATE
  $strdepday="";
  for ($i=1;$i<32;$i++) {
    $strdepday.="<option value=\"$i\"";
    if ($i==$gdepday) {$strdepday.=" selected";}
    $strdepday.=">$i</option>";
  }
  $strdepmonth="";
  for ($i=1;$i<13;$i++) {
    $strdepmonth.="<option value=\"$i\"";
    if ($i==$gdepmonth) {$strdepmonth.=" selected";}
    $strdepmonth.=">".$months[$i]."</option>";
  }
  $strdepyear="";
  for ($i=$yrmin;$i<=$yrmax;$i++) {
    $strdepyear.="<option value=\"$i\"";
    if ($i==$gdepyear) {$strdepyear.=" selected";}
    $strdepyear.=">$i</option>";
  }
  //KEEP THE VALUES FOR ROOM 1
  $strroom1qty="";
  for ($i=0;$i<6;$i++) {
    $strroom1qty.="<option value=\"$i\"";
    if ($i==$groom1qty) {$strroom1qty.=" selected";}
    $strroom1qty.=">$i</option>";
  }
  $strroom1type="";
  for ($i=0;$i<6;$i++) {
    $strroom1type.="<option value=\"$i\"";
    if ($i==$groom1type) {$strroom1type.=" selected";}
    $strroom1type.=">".$rooms[$i]."</option>";
  }
  //KEEP THE VALUES FOR ROOM 2
  $strroom2qty="";
  for ($i=0;$i<6;$i++) {
    $strroom2qty.="<option value=\"$i\"";
    if ($i==$groom2qty) {$strroom2qty.=" selected";}
    $strroom2qty.=">$i</option>";
  }
  $strroom2type="";
  for ($i=0;$i<6;$i++) {
    $strroom2type.="<option value=\"$i\"";
    if ($i==$groom2type) {$strroom2type.=" selected";}
    $strroom2type.=">".$rooms[$i]."</option>";
  }
?>
<html>
<head>
  <title>Braeside Hotel :: Contact Us</title>
  <meta name="author" content="Ivan Oliver">
  <meta name="copyright" content="2004/5 Ivan Oliver">
  <meta name="keywords" content="braeside hotel, braeside guesthouse, braeside guest house, guesthouse, guest house, exeter, devon, england, vacation, holiday, b&b, bed & breakfast, bed and breakfast, southwest, historic">
  <meta name="description" content="The web site of the Braeside Hotel in Exeter, Devon, UK">
  <meta name="robots" content="follow,index">
  <meta name="robots" content="archive">
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <link rel="shortcut icon" type="image/ico" href="http://www.braesidehotel.pwp.blueyonder.co.uk/shortcut.ico">
  <link rel="stylesheet" type="text/css" href="mainpage.css" />
  <script language="JavaScript" src="scripts.js" type="text/javascript"></script>
</head>
<body onLoad="Preload('gfx/b_tl.gif','gfx/b_t.gif','gfx/b_tr.gif','gfx/b_l.gif','gfx/b_r.gif','gfx/b_bl.gif','gfx/b_b.gif','gfx/b_br.gif','gfx/m_home1.gif','gfx/m_aboutus1.gif','gfx/m_howtofindus1.gif','gfx/m_ourpricelist1.gif','gfx/m_facilities1.gif','gfx/m_contactus1.gif')">
  <center>
    <?php include("header.php"); ?>
    <table width="770" cellspacing="0" cellpadding="0" border="0">
      <tr>
        <td width="170" valign="top">
          <?php include("menu.php"); ?>
        </td>
        <td width="600" valign="top">
          <table width="100%" cellspacing="0" cellpadding="0" border="0"><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <tr>
              <td width="28" height="28" background="gfx/b_tl.gif"><img src="gfx/b_spacer.gif" alt="" width="1" height="1" /></td>
              <td height="28" background="gfx/b_t.gif"><img src="gfx/b_spacer.gif" alt="" width="1" height="1" /></td>
              <td width="28" height="28" background="gfx/b_tr.gif"><img src="gfx/b_spacer.gif" alt="" width="1" height="1" /></td>
            </tr>
            <tr>
              <td width="28" background="gfx/b_l.gif"><img src="gfx/b_spacer.gif" alt="" width="1" height="1" /></td>
              <td>
                <table width="100%" cellspacing="0" cellpadding="0" border="0" class="cream">
                  <? if ($sendemail==true) { ?>
                  <tr><td align="center"><br /><b>Thank-you <?=$gname?></b><br /><br />Your email query has been sent.  We'll reply as soon as possible.<br /><br /></td></tr>
                  <? } else { ?>
                  <tr><td align="center" colspan="3"><img src="gfx/ph_contactus.gif" alt="Contact Us" width="130" height="42" border="0" /><br /></td></tr>
                  <tr><td align="center" colspan="3"><b><?php if (empty($message)) {echo "Please complete the following form:";} else {echo "<font color=\"#c00000\">$message</font>";} ?></b><br /><br /></td></tr>
                  <tr><td align="right">Your Name</td><td> </td><td align="left"><input type="text" name="name" size="40" value="<?=stripslashes($gname)?>" class="textbox" /> <font color="#c00000"><b>*</b></font></td></tr>
                  <tr><td align="right">Contact Email</td><td> </td><td align="left"><input type="text" name="email" size="40" value="<?=stripslashes($gemail)?>" class="textbox" /> <font color="#c00000"><b>*</b></font></td></tr>
                  <tr><td align="right">Phone Number</td><td> </td><td align="left"><input type="text" name="phone" size="40" value="<?=stripslashes($gphone)?>" class="textbox" /></td></tr>
                  <tr><td colspan="5"> </td></tr>
                  <tr>
                    <td align="right">Arrival Date</td><td> </td><td align="left"><select name="arrday" class="button"><?=$strarrday?></select>
                      <select name="arrmonth" class="button"><?=$strarrmonth?></select>
                      <select name="arryear" class="button"><?=$strarryear?></select></td>
                  </tr>
                  <tr>
                    <td align="right">Departure Date</td><td> </td><td align="left"><select name="depday" class="button"><?=$strdepday?></select>
                      <select name="depmonth" class="button"><?=$strdepmonth?></select>
                      <select name="depyear" class="button"><?=$strdepyear?></select></td>
                  </tr>
                  <tr><td align="right">Nights</td><td> </td><td align="left"><input type="text" name="numnights" size="2" maxlength="2" value="<?=$numnights?>" class="textbox"></td></tr>
                  <tr><td colspan="5"> </td></tr>
                  <tr><td align="right">Adults</td><td> </td><td align="left"><input type="text" name="numadults" size="2" maxlength="2" value="<?=$numadults?>" class="textbox"></td></tr>
                  <tr><td align="right">Children</td><td> </td><td align="left"><input type="text" name="numchildren" size="2" maxlength="2" value="<?=$numchildren?>" class="textbox"></td></tr>
                  <tr><td colspan="3"> </td></tr>
                  <tr>
                    <td align="right">Rooms Required</td><td> </td><td align="left"><select name="room1qty" class="button"><?=$strroom1qty?></select>
                    <select name="room1type" class="button"><?=$strroom1type?></select></td>
                  </tr>
                  <tr>
                    <td align="right"> </td><td> </td><td align="left"><select name="room2qty" class="button"><?=$strroom2qty?></select>
                    <select name="room2type" class="button"><?=$strroom2type?></select></td>
                  </tr>
                  <tr><td colspan="3"> </td></tr>
                  <tr><td align="right" valign="top">Query or<br />Comment</td><td> </td><td align="left" valign="top"><textarea rows="7" cols="70" name="query" class="button"><?=stripslashes($gquery)?></textarea> <font color="#c00000"><b>*</b></font></td></tr>
                  <tr><td colspan="3"> </td></tr>
<?php /*
                  <tr>
                    <td colspan="3" align="center">
                      <table cellspacing="0" cellpadding="0" border="0">
                        <tr>
                          <td><img src="makeimg.php" alt="" width="130" height="34" border="0" /></td><td> Please enter the six characters in the image: <input type="text" name="vcode" size="8" maxlength="6" class="textbox" /></td>
                        </tr>
                      </table>
                    </td>
                  </tr> */
?>
                  <tr><td colspan="3"> </td></tr>
                  <tr><td colspan="3" align="center"><input value=" Submit " name="submit" type="submit" class="button" /></td></tr>
                  <tr>
                    <td colspan="3" align="center"><br />
                      Telephone & facsimile<br /><b>+44 (0) 1392 256875</b><br /><br />Postal address<br /><b>21 New North Road, Exeter, Devon, EX4 4HF, United Kingdom</b><br /><br />
                      <font size="1">Want to comment about the site?  Contact the <a href="http://www.pictureinthesky.net" title="Visit www.pictureinthesky.net" target="_blank">webmaster</a><br />
                      All photographs are copyright ©2004-2007 Ivan Oliver</font>
                    </td>
                  </tr>
                  <? } ?>
                </table>
              </td>
              <td width="28" background="gfx/b_r.gif"><img src="gfx/b_spacer.gif" alt="" width="1" height="1" /></td>
            </tr>
            <tr>
              <td width="28" height="28" background="gfx/b_bl.gif"><img src="gfx/b_spacer.gif" alt="" width="1" height="1" /></td>
              <td height="28" background="gfx/b_b.gif"><img src="gfx/b_spacer.gif" alt="" width="1" height="1" /></td>
              <td width="28" height="28" background="gfx/b_br.gif"><img src="gfx/b_spacer.gif" alt="" width="1" height="1" /></td>
            </tr>
          </table>
          </form>
        </td>
      </tr>
    </table>
  </center>
</body>
</html>

That didn't work - the session_start() is in the db_connect.php file also as well as in the makeimg.php file.

 

http://braeside.pictureinthesky.net/contactus.php

 

I've enabled the captcha routine.

 

C: The session variable (always empty!)

V: What the user enters

FIXED!!!

 

Don't know why but I've not had to make this change on the other sites that use exactly the same captcha script.

 

All I did was move the following line AFTER header():

$_SESSION['vercode']=md5($strText);

 

Some reason the header setting the file to PNG was losing all of the session variables.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.