Hi All,I got stumped on something strange regarding a SQL database function being called from a PHP file.I transferred a site from one hosting company to another and downloaded all the web site files and exported the SQL databaseas usual. Then on the new hosting platform uploaded the site files and imported that same SQL database and then changed the SQL connection string to the new database configuration and evrything on the site looked to work just fine.I then had a few people tell me they could not submit the contact request form and thought, well I have done SQL database transfers before without issues after changing the connection string to the new database settings.If everything else was EXACTLY the same code, file names, etc.. why would the contavt form not submit?I checked and in the SQL DB there are two CAPTCHA tables named: captchas and captcha_tempThe table named ' captchas ' has 3 fields labeled capid, question and answer. The table named ' captcha_temp ' has 4 fields labeled ctid, capid,sessid and rndkey .Of course I spent hours going through all the PHP files that call to the SQL DB and could not find a field for something called $ans_key and then in a string see a $cap_ans, but that is not a field in the table named ' captcha ' that it looks how it is written.In the PHP code here you can see a hash key or something for $ans_key, but do not see a field in any table in the SQL DB labeled $ans_key.<?php include("access/include/functions.php"); include("access/include/session.php"); require_once("captcha/class.captcha.php"); // ===================================================PRocess Mailform ///////// Contact /////////--> $sessid=session_id(); foreach($_POST as $key=>$value) { $$key = $value; //echo"--// $key = $value<br>"; } // echo"--------------------------------------// Session";/* foreach($_SESSION as $key=>$value) { $$key = $value; echo"$key = $value<br>"; } */ //$ans_key='52c6cdb12f358c0ad6c4be46e4e62dac'; // $sessid=$_SESSION['sessid']; //lets validate then destroy the temp record in the captchas if(!$capid)$capid=$cap_id; $db=$database->connection; $captcha = new Text_Captcha($db); if (!$captcha->validate($cap_ans,$capid,$ans_key)){ $step2=false; $errmsg=true; }else{ $captcha->deleteTempKey($capid, $sessid); } if($step2){ // LET's LOG this INFO ==============================================================// $admin_errmsg=array(); $contact="$title $firstname $lastname"; $_SESSION['contact']="$title $lastname";and so on...
Then in the class.captcha.php file called on there is nothing I see wrong, but I am an Amatuer..<?phpclass Text_Captcha{ // Reference to the database connection where the `captchas` table resides var $db_conn = false; // Error message var $err_msg = ""; //var $connection; /** * Constructs the class * @param $db - Reference to the database connection where the `captchas` table resides */ function Text_Captcha(&$db = null) { global $tryover,$sessid; if (!empty($db)) $this->db_conn = $db; if($tryover){ $this->sessid=$sessid; }else $this->sessid=session_id(); } /** * Randomly find one single question */ function get_question() { global $tryover; $ret = false; if ($this->db_conn) { // Count questions exist $query = "SELECT COUNT(*) AS count_all FROM captchas"; $result = mysql_query($query, $this->db_conn); $data = mysql_fetch_array($result); $q_count = $data["count_all"]; mysql_free_result($result); // Get one random row $query = "SELECT * FROM captchas LIMIT " . (rand(0, $q_count-1)) . ", 1"; $result = mysql_query($query, $this->db_conn); $data = mysql_fetch_array($result); $ret = $data["question"]; $captcha_id = $data["capid"]; mysql_free_result($result); // Persist captcha ID $sessid=$this->sessid; $this->persist_id($captcha_id,$sessid); $rndkey=$this->setTempKey($captcha_id,$sessid); if(!$rndkey) $this->err_msg = "Key not posted"; } else { $this->err_msg = "Can not find database connection"; } $output=array($ret,$rndkey,$captcha_id); return $output; } /** * Validate user submitted CAPTCHA answer * @param $answer - user answer */ function validate($answer,$capid,$rndkey) { // $captcha_id = $this->persisted_id('id'); //this will not work over ajax; $safeid=mysql_escape_string($captcha_id); $sessid=$this->persisted_id('sess'); $answer_ok = false; if (strlen($answer) > 0) { if ($this->db_conn) { $query = " SELECT c.*, t.* FROM captchas c, captcha_temp t WHERE c.capid=t.capid AND c.capid ='$capid' AND t.rndkey='$rndkey'"; //echo "<br>$query<br>"; AND t.sessid='$sessid'"; $result = mysql_query($query, $this->db_conn); if($result) { $data = mysql_fetch_array($result); $db_answer = $data["answer"]; if($db_answer){ // Match answer $arr_answers = split(":", $db_answer); for ($i = 0; $i < count($arr_answers); $i++) { $check_against = $arr_answers[$i]; if (preg_match("/\b$check_against\b/i", $answer)) { $answer_ok = true; break; } } }else{ $this->err_msg = "Empty answer"; } }else{ $this->err_msg = "Question doesn't exist"; } mysql_free_result($result); }else{ $this->err_msg = "Can not find database connection"; } }else{ $this->err_msg = "Empty answer"; } //update the randkey with new vars/* if(!$answer_ok){ $this->updateTempKey($capid); } */ return $answer_ok; } /** * Method for retrieving persisted TEMP ID * * @access private */ function deleteTempKey($capid, $sessid) { global $database; $table="captcha_temp"; $criteria="sessid='$sessid'"; $result =$database->deleteUser($table,$criteria); if($result) return $rndkey; else return false; } function setTempKey($capid,$sessid) { global $session; $rndkey=$session->generateRandID(); $query = "INSERT INTO captcha_temp (capid, sessid,`rndkey`) VALUES ($capid, '$sessid','$rndkey')"; $result =mysql_query($query, $this->db_conn); if($result) return $rndkey; else return false; } function updateTempKey($capid) { global $database,$session; $fvalue=$session->generateRandID();//$rndkey $table="captcha_temp"; $fname="`rndkey`"; $idfield= 'capid'; $idval=$capid; $result =$database->updateField($table,$fname,$fvalue,$idfield,$idval ); if($result) { return $fvalue; }else return false; } /** * Method for persiting currently showing CAPTCHA_ID * This is only example, you should make use the server to persist this ID, instead of cookie in the client * Normally you'd like to override this method to implement a safer mechanism, * ie. database session variables storage, temp. table, etc. * * @param $id - CAPTCHA ID * @access private */ function persist_id($id,$sessid){ $_SESSION["captcha_id"] = $id; $_SESSION["sessid"] = $sessid; } /** * Method for retrieving persisted CAPTCAH ID * * @access private */ function persisted_id($what){ if($what=='id'){ $out=$_SESSION["captcha_id"]; }else{ $out=$_SESSION["sessid"]; } return $out; } }//end class?>
Can anyone see anything or point me in a direction to follow as the files and forms are exactly the same as when they wereworking on the previous hosting account..Count a pathway have changed from the previous ' .. ' that some calls make or could have a field been corrupted? Or do I need todo something to add the $ans_key field and hash somewhere in the SL DB as I can not find that?Pulling the last of my hair out so I hope one of you Wizards can tell me what you see or if it could be something like a new hosting company needing to check to ensure I am on a certain PHP scripting platform, etc...Thanks in advance!!!JayJames Smith