473,701 Members | 2,918 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

register and login email process looping indefinitely

11 New Member
I'm really new to the whole networking side of things, so I don't know the backend very well. I wrote a series of PHP/AJAX scripts to allow a user to create a login account, but apparently my script is doing much much more than I imagined as I received an email from my admin this morning:

Your script located at .....Scripts/form_check.php has been moved to your account root. This script generated over 7000 emails that bounced back and forth on our server for an hour, which drive the load on this machine to inappropriate levels. Every time this script runs, it also core dumps on the server:

-rw------- 1 squeez7 squeez7 24M Mar 3 21:47 core.14811
-rw------- 1 squeez7 squeez7 24M Mar 3 21:51 core.15255
I think a core dump means my program had a fatal error, and I know my program is supposed to email me when there is an error. Granted, I was debugging the script last night, but I had no idea this was going on! Especially as my mailing code is the same code I have used before without issue.

I'm scared to run this code again even to test it, but I've been over it a million times, and I still have no clue what is causing this.

I would really appreciate any help!!!

List of scripts:
  • ajax.js
  • form_check.php
  • UsrDB.php
  • BasicDB.php

Here are my scripts:

ajax.js
Expand|Select|Wrap|Line Numbers
  1. /**********************************
  2.     Filename:    ajax.js
  3.     Date:            02.25.08
  4. **********************************/
  5.  
  6. /***** CREATE XMLHTTP OBJECT *****/
  7. function request() {
  8.     var browser = navigator.appName;        // get browser
  9.     var req = false;
  10.     if(browser == "Microsoft Internet Explorer") {    // IE
  11.         try {
  12.             req = new ActiveXObject("Msm12.XMLHTTP");        // -- Msm12
  13.         } catch(err1) {
  14.             try {
  15.                 req = new ActiveXObject("Microsoft.XMLHTTP");    // -- Microsoft
  16.             } catch(err2) {
  17.                 req = false;        // FAIL!
  18.             }
  19.         }
  20.     } else {
  21.         try {
  22.             req = new XMLHttpRequest();    // not IE
  23.         } catch(err) {
  24.             req = false;
  25.         }
  26.     }
  27.  
  28.     return req;
  29. }
  30.  
  31. var http = request();        // CREATE XMLHTTP object
  32.  
  33. var obj;                            // other variables
  34. var obj2;
  35. var url;
  36.  
  37. /***** SEND AJAX REQUEST *******/
  38. function send_post(params,use) {
  39.     http.open("POST", url, true);
  40.     http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  41.     http.setRequestHeader("Content-length", params.length);
  42.     http.setRequestHeader("Connection", "close");
  43.     http.onreadystatechange = eval(use);
  44.     http.send(params);
  45. }
  46.  
  47. /********************************************************************************
  48. ***** USE FUNCTIONS *************************************************************
  49. ********************************************************************************/
  50.  
  51. /***** FORM *****/
  52. function form_response() {
  53.     var vobj = "v"+obj;
  54.     if(http.readyState == 4) {
  55.         if(http.status == 200) {
  56.             var data = http.responseText.split(",");
  57.             if(data[0] == 2) {        // no data -- do nothing
  58.             } else if(data[0] == 0) {    // good data -- show check
  59.                 document.getElementById(vobj).innerHTML = "<img class=\"form_img\" src=\"../images/yes.png\"/>";
  60.             } else {        // bad data -- show x and response
  61.                 document.getElementById(vobj).innerHTML = data[1]+" <img class=\"form_img\" src=\"../images/no.png\"/>";
  62.             }
  63.         } else {
  64.             document.getElementById(vobj).innerHTML = "No server response.";
  65.             //document.getElementsByName(obj)[0].className = "maybe";
  66.         }
  67.     } else {
  68.         document.getElementById(vobj).innerHTML = 'Checking...';
  69.         //document.getElementsByName(obj)[0].className = "maybe";
  70.     }
  71. }
  72.  
  73. /***** REGISTER *****/
  74. function register_response() {
  75.     obj = 'message';    // set div id
  76.     var msg = '';
  77.     if(http.readyState == 4) {
  78.         if(http.status == 200) {
  79.             var data = http.responseText;
  80.             document.getElementById(obj).innerHTML = data;
  81.         } else {
  82.             document.getElementById(obj).innerHTML = "Unable to complete request.";
  83.         }
  84.     } else {
  85.         document.getElementById(obj).innerHTML = "Working";
  86.     }
  87. }
  88.  
  89.  
  90. /********************************************************************************
  91. ***** CHECK FUNCTIONS ***********************************************************
  92. ********************************************************************************/
  93.  
  94. /* EMAIL */
  95. function check_email() {
  96.     url = "../Scripts/form_check.php";
  97.     obj = "email";
  98.     if(document.getElementsByName(obj)[0].value != '') {
  99.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  100.         send_post(params,"form_response"); }
  101. }
  102.  
  103. /* USR */ 
  104. function check_usr() {
  105.     url = "../Scripts/form_check.php";
  106.     obj = "usr";
  107.     if(document.getElementsByName(obj)[0].value != '') {
  108.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  109.         send_post(params,"form_response"); }
  110. }
  111.  
  112. /* FIRST */
  113. function check_first() {
  114.     url = "../Scripts/form_check.php";
  115.     obj = "first";
  116.     if(document.getElementsByName(obj)[0].value != '') {
  117.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  118.         send_post(params,"form_response"); }
  119. }
  120.  
  121. /* LAST */
  122. function check_last() {
  123.     url = "../Scripts/form_check.php";
  124.     obj = "last";
  125.     if(document.getElementsByName(obj)[0].value != '') {
  126.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  127.         send_post(params,"form_response"); }
  128. }
  129.  
  130. /* PASSWORD */
  131. function check_password() {
  132.     url = "../Scripts/form_check.php";
  133.     obj = "password";
  134.     if(document.getElementsByName(obj)[0].value != '') {
  135.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value;
  136.         send_post(params,"form_response"); }
  137. }
  138. function check_confirm() {
  139.     url = "../Scripts/form_check.php";
  140.     obj = "confirm";
  141.     obj2 = "password";
  142.     if(document.getElementsByName(obj)[0].value != '') {
  143.         var params = "object="+obj+"&data="+document.getElementsByName(obj)[0].value+
  144.             "&data2="+document.getElementsByName(obj2)[0].value;
  145.         send_post(params,"form_response"); }
  146. }
  147.  
  148. /* REGISTER */
  149. function register() {
  150.     url = "../Scripts/register.php";
  151.  
  152.     if(document.getElementsByName('usr')[0].value != 0 &&
  153.             document.getElementsByName('email')[0].value != 0 &&
  154.             document.getElementsByName('first')[0].value != 0 &&
  155.             document.getElementsByName('last')[0].value != 0) {
  156.         params = "usr="+document.getElementsByName('usr')[0].value+
  157.             "&email="+document.getElementsByName('email')[0].value+
  158.             "&first="+document.getElementsByName('first')[0].value+
  159.             "&last="+document.getElementsByName('last')[0].value;
  160.         send_post(params,"register_response");
  161.     }
  162. }
  163.  
  164. /* LOGIN */
  165. function login() {
  166.     url = "../Scripts/login.php";
  167.  
  168.     if(document.getElementsByName('name')[0].value != 0 &&
  169.         document.getElementsByName('password')[0].value != 0) {
  170.         params = "name="+document.getElementsByName('name')[0].value+
  171.             "&password="+document.getElementsByName('password')[0].value;
  172.  
  173.         send_post(params,"register_response");
  174.     }
  175. }
  176.  

form_check.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. /**********************************
  4.     Filename:    form_check.php
  5.     Date:            02.25.08
  6. **********************************/
  7.  
  8. require_once("../Classes/Sys.php");
  9. require_once("../Classes/Usr.php");
  10. require_once("../Classes/UsrDB.php");
  11.  
  12. session_start();
  13. header("Cache-control: private"); 
  14.  
  15. $db = new UsrDB($_SESSION['sys'],$_SESSION['usr']);
  16.  
  17. $return = "1,Invalid data";
  18.  
  19. if($_POST['data'] == '') {
  20.     echo "2,No data";
  21. }
  22.  
  23. switch($_POST['object']) {
  24.     case "usr":
  25.         if($db->verify_usr($_POST['data'])) {
  26.             $return = "1,Existing user name"; }
  27.         else {
  28.             $return = "0,Available user name"; }
  29.         break;
  30.     case "email":
  31.         $find = "/[\w\d\_\-\.]*\@[\w\d\_\-\.]*\.(com|edu|gov|net|co)/";
  32.         if(!preg_match($find,$_POST['data'])) {
  33.             $return = "1,Invalid email"; }
  34.         else {
  35.             if($db->verify_email($_POST['data'])) {
  36.                 $return = "1,Existing email"; }
  37.             else {
  38.                 $return = "0,Available email"; }
  39.         }
  40.         break;
  41.     case "first":
  42.     case "last":
  43.         $find = "/[^a-zA-Z]/";
  44.         if(preg_match($find,$_POST['data'])) {
  45.             $return = "1,Invalid string"; }
  46.         else {
  47.             $return = "0,Valid string"; }
  48.         break;
  49.     case "password":
  50.         $find = "/\s/";
  51.         if(preg_match($find,$_POST['data'])) {
  52.             $return = "1,Invalid password"; }
  53.         else {
  54.             $return = "0,Valid password"; }
  55.         break;
  56.     case "confirm":
  57.         if($_POST['data'] == $_POST['data2']) {
  58.             $return = "0,Passwords match"; }
  59.         else {
  60.             $return = "1,Passwords don't match"; }
  61.         break;
  62.     default:
  63.         break;
  64. }
  65.  
  66. echo $return;
  67.  
  68. ?>
  69.  
I'll have to put the last two files in the following post.
Mar 4 '08 #1
5 2571
muppetjones
11 New Member
Here's UsrDB.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. /**********************************
  4.     Filename:    UsrDB.php
  5.     Date:            02.25.08
  6. **********************************/
  7.  
  8. require_once('BasicDB.php');    
  9.  
  10. class UsrDB extends BasicDB {    
  11.  
  12. /* CLASS VARIABLES */
  13.     protected $group;    // denotes project & permissions set
  14.     private $system;    // instance of the system class
  15.     private $user;    // instance of the user class
  16.     private $webmaster;    // email to send error messages to
  17.     private $date;    // date
  18.     private $day;    // day
  19.     private $time;    // time
  20.  
  21. /* PUBLIC FUNCTIONS */
  22.  
  23. /*********************************************************************** 
  24. ***** CONSTRUCTOR & DESTRUCTOR ***************************************** 
  25. ***********************************************************************/
  26.  
  27. /*********************************************************************** 
  28. Constructor
  29.         input: instance of the system and user classes
  30.         output: none */
  31.     public function __construct($sys,$usr) {    
  32.         $this->system    = $sys;    // System class
  33.         $this->user        = $usr;    // Usr class
  34.         $this->group     = $this->system->group();    // GET system group
  35.         $this->day        = date("Y:m:d");    
  36.         $this->time        = date("H:i:s");    
  37.         $this->date        = $day."::".$time;    
  38.         $this->webmaster = "webmaster@------.com";    
  39.     }     // END Constructor
  40.  
  41. public function __destruct() {    }    
  42.  
  43.  
  44. /*********************************************************************** 
  45. ***** ERROR HANDLING FUNCTIONS ***************************************** 
  46. ***********************************************************************/
  47.  
  48. /*********************************************************************** 
  49. Write_log($m)
  50.         input: instruction (Error,LogIN,LogOUT,etc.), and message
  51.         output: TRUE / FALSE
  52.         */
  53.     public function write_log($instruction,&$msg) {    
  54.         /* LOG MESSAGE QUERY */
  55.         $query = sprintf("INSERT INTO log (ses_id, log_date, log_time, log_msg, log_instruction)
  56.             VALUES ( '%s', '%s', '%s', '%s', '%s' )",                    // CREATE mysql query
  57.                 $this->system->id(),
  58.                 $this->day,
  59.                 $this->time,
  60.                 $msg,
  61.                 $instruction);    
  62.         if(!$this->insert($query)) {    // IF our query has errors
  63.             $to    = $this->webmaster;    
  64.             $subj    = "[".$this->group."] Error";    
  65.             $msg = "Function: write_log\n".
  66.                 "Problem: Unable to write to database\n".
  67.                 "Date: ".$this->date."\n".
  68.                 "User: ".$this->user->name();    
  69.             $from    = "From: ".$this->webmaster;    
  70.             mail($to,$subj,$msg,$from);    //    --NOTIFY the webmaster
  71.             return false;    //    --RETURN FALSE
  72.         }    
  73.  
  74.         return true;    // RETURN true
  75.     }     // END log_err
  76.  
  77.  
  78. /*********************************************************************** 
  79. ***** USRDB METHODS **************************************************** 
  80. ***********************************************************************/
  81.  
  82. /***login removed for space */
  83.  
  84. /*********************************************************************** 
  85. logout()
  86.         input: none
  87.         output: none
  88.         result: */
  89.     public function logout() {    
  90.         $this->system->__destruct();    // KILL system instance
  91.         unset($this->system);    // UNSET system instance
  92.         $this->write_log("Log","OUT ".$this->user->name());    // LOG log out
  93.     }     // END logout
  94.  
  95. /*********************************************************************** 
  96. register()
  97.         input: array of user name, first & last name, and email
  98.         output: true if success, false if fail */
  99.     public function register($input_array) {    
  100.         $usr         = $this->mysql_safe($input_array['usr']);    // SECURE user input
  101.         $first    = $this->mysql_safe($input_array['first']);    
  102.         $last        = $this->mysql_safe($input_array['last']);    
  103.         $email    = $this->mysql_safe($input_array['email']);    
  104.         $msg        = '';    
  105.         $row;    
  106.  
  107.         $query = sprintf("INSERT INTO usr (usr_name,usr_fname,usr_lname,usr_email)
  108.             VALUES (%s,%s,%s,%s)",                    // QUERY add user
  109.                 $usr,
  110.                 $first,
  111.                 $last,
  112.                 $email);    
  113.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  114.  
  115.         $query = sprintf("SELECT usr_id FROM usr WHERE usr_name = %s",$usr);    // QUERY get user id
  116.         if(!($row = $this->select($query))) {     return false;     }    // RUN query, FALSE if bad
  117.         $id = $row['usr_id'];    // SAVE user id
  118.  
  119.         $password = $this->random_password();    // CREATE random password
  120.         $query = sprintf("INSERT INTO pswd (p_pswd,usr_id) VALUES ('%s',%d)",    // QUERY add encrypted password
  121.                 sha1($password),
  122.                 $id);    
  123.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  124.  
  125.         $query = sprintf("INSERT INTO usr_grp (usr_id,usrg_grp,usrg_rank) ".    // QUERY insert user into group
  126.                     "VALUES (%d,'%s',%d)",
  127.                 $id,
  128.                 $this->group,
  129.                 1);    
  130.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  131.  
  132.         $query = sprintf("INSERT INTO usr_meta (usr_id) VALUES (%d)",    // QUERY add user row in meta table
  133.             $id);    
  134.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  135.  
  136.         $this->welcome($email,$usr,$password);    // SEND welcome email with password
  137.         $this->write_log("Register",$usr);    // LOG register
  138.  
  139.         return true;    
  140.     }     // END register
  141.  
  142. /*********************************************************************** 
  143. session()
  144.         input: none
  145.         output: TRUE / FALSE */
  146.     public function session() {    
  147.         if(!$this->system->verify_id() || !$this->system->verify_ip()) {    // IF we still have the same creds
  148.             $this->logout();    //    --LOGOUT
  149.             return false;    }    //    --RETURN false
  150.  
  151.         // Add session to database
  152.         $query = sprintf("INSERT INTO session (usr_id,ses_grp,ses_ip,ses_addr,ses_php,ses_date,ses_time)
  153.             VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s' )",    // QUERY add session data
  154.                 $this->user->id(),
  155.                 $this->group,
  156.                 $this->system->ip(),
  157.                 $this->system->addr(),
  158.                 $this->system->id(),
  159.                 $this->day,
  160.                 $this->time);    
  161.         if(!$this->insert($query)) {     return false;     }    // RUN query, FALSE if bad
  162.         return true;    // RETURN true
  163.     }     // END session
  164.  
  165. /*********************************************************************** 
  166. welcome
  167.         input: email, user name, password
  168.         output: welcome email and password email  */
  169.     public function welcome($email,$usr,$password) {    
  170.         $to    = $email;    
  171.         $subj = "Welcome to ".$this->group;    
  172.         $from    = "From: ".$this->webmaster;    
  173.         $msg    = "
  174.             Dear $usr,
  175.     ***nice message here ***    
  176.  
  177.             ";    
  178.         mail($to,$subj,$msg,$from);    // SEND welcome email
  179.         mail($to,$subj,$password,$from);    // SEND password email
  180.         return true;    // RETURN true
  181.     }    // END welcome
  182.  
  183.  
  184. /*********************************************************************** 
  185. ***** VERIFY FUNCTIONS ************************************************* 
  186. ***********************************************************************/
  187.  
  188. /*********************************************************************** 
  189. verify_email
  190.         input: email
  191.         output: true | false */
  192.     public function verify_email($email) {    
  193.         $email = $this->mysql_safe($email);    // SECURE user input
  194.         $query = sprintf("SELECT usr_id FROM usr WHERE usr_email = %s",    // QUERY check if email is in database
  195.                     $email);    
  196.         if(!($row = $this->select($query))) {     return false;     }    // RUN query, FALSE if not
  197.         else {     return true;     }    // TRUE if it is
  198.     }    
  199.  
  200. /*********************************************************************** 
  201. verify_usr
  202.         input: user name
  203.         output: true | false   */
  204.     public function verify_usr($usr) {    
  205.         $usr = $this->mysql_safe($usr);    // SECURE user input
  206.         $query = sprintf("SELECT usr_id FROM usr WHERE usr_name = %s",    // QUERY check if user name is in database
  207.                     $usr);    
  208.         if(!($row = $this->select($query))) {     return false;     }    // RUN query, FALSE if not
  209.         else {     return true;     }    // TRUE if it is
  210.     }    
  211.  
  212. /*********************************************************************** 
  213. ***** UPDATE FUNCTIONS ************************************************* 
  214. ***********************************************************************/
  215.  
  216. // removed for space
  217.  
  218. /*********************************************************************** 
  219. ***** GET FUNCTIONS **************************************************** 
  220. ***********************************************************************/
  221.  
  222. /*********************************************************************** 
  223. get_list()
  224.         input: desired attribute, minimum rank (opt)
  225.         output: array of user names */
  226.     public function get_user_list() {     return $this->get_list("usr_name");     }    // ALIAS for get_list USER
  227.     public function get_email_list() {     return $this->get_list("usr_email");     }    // ALIAS for get_list EMAIL
  228.     public function get_list() {    
  229.         $val = func_get_arg(0);    // SAVE desired attribute
  230.         if(func_num_args() == 2) {    // IF more input
  231.             $min_rank = func_get_arg(1);     }    //    --SAVE desired rank
  232.         else {     $min_rank = 1;     }    // ELSE get all ranks
  233.         $query = sprintf("SELECT %s FROM usr WHERE usr_rank >= %d",    // QUERY get all rows
  234.                     $val,
  235.                     $min_rank);    
  236.         if(!($list = $this->select_simple_list($query))) {     return false;     }    // SAVE rows as a array, FALSE on fail
  237.         return $list;    // RETURN array
  238.     }     // END get_list
  239.  
  240. /*********************************************************************** 
  241. random_password()
  242.         input: none
  243.         output: password generated */
  244.     public function random_password() {    
  245.                                     // CREATE character arrays
  246.         $letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');    
  247.         $numbers = array('1','2','3','4','5','6','7','8','9','0');    
  248.         $symbols = array('!','@','#','$','%','^','&','*','(',')','<','>','.','?','/',':','{    ','}    ',',','.',';    ','|','+','=','~');    
  249.         $length     = 10;    
  250.         $password = '';    
  251.  
  252.         for($i = 0;     $i <= $length;     $i++) {    // LOOP for given length
  253.             $set = mt_rand(0,2);    // CHOOSE which array to use
  254.             if($set == 0) {    // IF letters
  255.                 $char = mt_rand(1,count($letters));    //    --GENERATE a random value
  256.                 $char--;    // --DECREMENT (to fit in array index)
  257.                 $password .= $letters[$char];    // --ADD to password
  258.             }     else if($set == 1) {    // IF numbers
  259.                 $char = mt_rand(1,count($numbers));    //    --see above
  260.                 $char--;    
  261.                 $password .= $numbers[$char];    
  262.             }     else if($set == 2) {    // IF symbols
  263.                 $char = mt_rand(1,count($symbols));    // -- see above
  264.                 $char--;    
  265.                 $password .= $symbols[$char];    
  266.             }     else {    }    
  267.         }    
  268.  
  269.         return $password;    // RETURN password
  270.     }     // END random_password
  271.  
  272. }     // END CLASS
  273.  
  274. ?>
  275.  
Mar 4 '08 #2
muppetjones
11 New Member
BasicDB.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. /**********************************
  4.     Filename:    BasicDB.php
  5.     Date:            02.25.08
  6. **********************************/
  7.  
  8. class BasicDB {    
  9.  
  10. /* CLASS VARIABLES */
  11.     private $date;    // Date in Y:m:d::H:i:s form
  12.     private $day;    // Day in Y:m:d form
  13.     private $system;    // instance of the system class
  14.     private $time;    // Time in H:i:s form
  15.     private $webmaster;    // Email to send error notifications to
  16.  
  17. /* CLASS FUNCTIONS */
  18.  
  19. /*********************************************************************** 
  20. ***** CONSTRUCTOR & DESTRUCTOR ***************************************** 
  21. ***********************************************************************/
  22.  
  23. /*********************************************************************** 
  24. Constructor
  25.         input: instance of the system class
  26.         output: none */
  27.     public function __construct($sys) {    
  28.         $this->day        = date("Y:m:d");    
  29.         $this->time        = date("H:i:s");    
  30.         $this->date        = $day."::".$time;    
  31.         $this->system    = $sys;    
  32.         $this->webmaster = "webmaster@-------.com";    
  33.     }     // END Constructor
  34.  
  35. /*********************************************************************** 
  36. ***** ERROR HANDLING FUNCTIONS ***************************************** 
  37. ***********************************************************************/
  38.  
  39. /*********************************************************************** 
  40. $this->err($msg)
  41.         input: error message
  42.         output:    email to the webmaster 
  43.                     write to log                     */
  44.     public function err($msg) {    
  45.         $to    = $this->webmaster;    // assign To:
  46.         $subj    = "[".$this->group."] Error";    // assign Subject:
  47.         $msg .= "\n".$this->date;    // assign Message:
  48.         $from    = "From: ".$this->webmaster;    // assign From:
  49.         mail($to,$subj,$msg,$from);    // send mail
  50.         $this->write_log("Error",$msg);    // log error
  51.     }     // END $this->err()
  52.  
  53. /*********************************************************************** 
  54. ***** MYSQL FUNCTIONS ************************************************** 
  55. ***********************************************************************/
  56.  
  57. /*********************************************************************** 
  58. DB_connect()
  59.         input: none
  60.         output: link resource */
  61.     public function db_connect() {    
  62.  
  63.         /* Squeeze of Lime server info*/
  64.         $server = "----------";    
  65.         $usr = '----------';    
  66.         $pswd = '----------';    
  67.         $db = '----------';    
  68.  
  69.         // opening db connection
  70.         $link = mysql_connect($server,$usr,$pswd);    // OPEN mysql connection
  71.         if(!$link) {    // IF no connection 
  72.             $this->err("db_connect(): Unable to connect to db.");    //    --REPORT error
  73.             return false;    //    --RETURN false
  74.         }     else {     }    // ELSE continue
  75.  
  76.         $dbselect = mysql_select_db($db, $link);    // SELECT database
  77.         if(!$dbselect) {    // IF no selection
  78.             $this->err("db_connect(): Unable to select db.");    //    --REPORT error
  79.             return false;    //    --RETURN false
  80.         }     else {     }    // ELSE continue
  81.  
  82.         return $link;    // RETURN link resource
  83.     }     // END db_connect()
  84.  
  85.  
  86. /*********************************************************************** 
  87. insert
  88.         input: mysql query string (insert, delete, or update)
  89.         output: query result (false on fail, true on success)     */
  90.     public function insert($query) {    
  91.         return $this->result($query,1,0);    // CALL result function
  92.     }    
  93.  
  94. /*********************************************************************** 
  95. select
  96.         input: mysql query string (select)
  97.         output: query result (false on fail, single result on success)  */
  98.     public function select($query) {    
  99.         return $this->result($query,0,0);    // CALL result function
  100.     }     // END select
  101.  
  102. /*********************************************************************** 
  103. select_simple_list
  104.         input: mysql query string (select)
  105.         output: query result (false on fail, array of single field on success) */
  106.     public function select_simple_list($query) {    
  107.         return $this->result($query,0,1);    // CALL result function
  108.     }     // END select_simple_list
  109.  
  110. /*********************************************************************** 
  111. result
  112.         input: mysql query string, boolean, boolean
  113.         output: */
  114.     public function result($query,$insert,$list) {    
  115.         $count = 0;    // RESET count
  116.         $link = $this->db_connect();    // GET a database link
  117.         $data;    // INITIALIZE variable
  118.  
  119.         if(!$link) {    // IF we still don't connect
  120.             $msg = "Function: check_result\n".    //    --CREATE error message
  121.                 "Problem: ".mysql_error()."\n".
  122.                 "Date: ".$this->date."\n";    
  123.             $this->err($msg);    //    --REPORT error
  124.             $this->logout();    //    --LOGOUT
  125.             return false;     }    //    --RETURN FALSE
  126.  
  127.         $count = 0;    // RESET count
  128.         $result = mysql_query($query,$link);    // QUERY database
  129.         if(!$result) {    // IF no result,
  130.             $msg = "Function: check_result\n".    //    --CREATE error message
  131.                 "Problem: ".mysql_error()."\n".
  132.                 "Date: ".$this->date."\n".
  133.                 "Query: $query";    
  134.             $this->err($msg);    //    --REPORT error
  135.             $this->logout();    //    --LOGOUT
  136.             return false;     }    //    --RETURN FALSE
  137.  
  138.         if($insert) {    // IF an insert type query
  139.             if(mysql_affected_rows() == 0) {    //    --CHECK for affected rows
  140.                 return false;     }    //    --NONE? return false
  141.             $data = true;    //    --OTHERWISE return true
  142.         }     else {    // ELSE a select type query
  143.             if(mysql_num_rows($result) == 0) {    //    --CHECK for number of rows
  144.                 return false;     }    //    --NONE? return false
  145.             else if($list) {    //    --ELSE IF we want a list
  146.                 while($row = mysql_fetch_row($result)) {    //    --LOOP through the rows returned
  147.                     $data[] = $row[0];     }    //    --SAVE first value in array
  148.             }     else {    //    --ELSE we want a single value
  149.                 $data = mysql_fetch_assoc($result);    //    --SAVE the query result
  150.             }    
  151.             mysql_free_result($result);    // FREE the result
  152.         }    
  153.  
  154.         mysql_close($link);    // CLOSE database link
  155.         return $data;    // RETURN our query data (if good result)
  156.     }    
  157.  
  158.  
  159. /*********************************************************************** 
  160. ***** SAFE FUNCTIONS *************************************************** 
  161. ***********************************************************************/
  162.  
  163. /*********************************************************************** 
  164. Mysql_safe($val)
  165.         input: a string
  166.         output: a safe, mysql 'executable' version of the string, in quotes
  167.         note: (adapted from php.net) */
  168.     public function mysql_safe($value) {    
  169.         $link = $this->db_connect();    // GET a database link
  170.         if (get_magic_quotes_gpc()) {     $value = stripslashes($value);     }    // IF gmqg is turned on, USE it
  171.         if (!is_numeric($value)) {    // IF its not a number
  172.             $value = "\"" . mysql_real_escape_string($value,$link) . "\"";     }    //    --ESCAPE and put in quotes
  173.         return $value;    //    --RETURN our safe string
  174.     }     // END mysql_safe
  175.  
  176. /*********************************************************************** 
  177. Mysql_safe_nq($val)
  178.         input: a string
  179.         output: a safe, mysql 'executable' version of the string, W/O quotes
  180.         note: (adapted from php.net) */
  181.     public function mysql_safe_nq($value) {    
  182.         $link = $this->db_connect();    // GET a database link
  183.         if (get_magic_quotes_gpc()) {     $value = stripslashes($value);     }    // IF gmqg is turned on, USE it
  184.         if (!is_numeric($value)) {    // IF its not a number
  185.             $value = mysql_real_escape_string($value,$link);     }    //    --ESCAPE the string
  186.         return $value;    //    --RETURN our safe string
  187.     }     // END mysql_safe
  188.  
  189. }     // END CLASS
  190.  
  191. ?>
  192.  
Mar 4 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
I don't think you developed this package yourself, otherwise you would have some clue as to where the problem lies or could even be pinpointed.

In my opinion you downloaded this package from one of the many sites like ringsworld who provide free scripts.

Ronald
Mar 4 '08 #4
muppetjones
11 New Member
Actually, I wrote the whole thing. This is the second version -- the first being a PHP4 version, but I now added in AJAX and the updated OOP handling in PHP (which is still not very good).

I don't know where the problem is because I don't know what would cause a core dump. And since I'm not getting the emails designed to help me debug the system, I have no idea where I'm going wrong.

What I don't understand is that I haven't really changed the emailing system (the err function in BasicDB), so I should be getting emails -- but neither my emails nor my registration emails are coming through. I did change hosts since the last working version, but I wouldn't expect that to effect why the emails are causing server issues instead of being sent out. Again, I really just don't know what is going on behind the scense. I have been all over this code, debugging it through messages returned in javascript alerts at one point =) (for the errors returned from the ajax-called php).

I am the programmer for this code, though -- I wrote every line and commented it all. The problem is I fear to test it anymore lest my admin suspend my account, I have no idea what causes a core dump, and I can't get to my debugging messages.

I would really appreciate some help if anyone has a chance.


Attached are the four files. For easier use, I deleted most of the tabs that aligned the comments (as is seen in the code pasted above). If anyone wants them, I have the files with the comments aligned on the right with tab=4 in Notepad2.
Attached Files
File Type: txt ajax.txt (5.4 KB, 307 views)
File Type: txt form_check.txt (1.5 KB, 316 views)
File Type: txt BasicDB.txt (7.1 KB, 315 views)
File Type: txt UsrDB.txt (18.5 KB, 327 views)
Mar 4 '08 #5
eddierosenthal
11 New Member
Actually, I wrote the whole thing. This is the second version -- the first being a PHP4 version, but I now added in AJAX and the updated OOP handling in PHP (which is still not very good).

I don't know where the problem is because I don't know what would cause a core dump. And since I'm not getting the emails designed to help me debug the system, I have no idea where I'm going wrong.

What I don't understand is that I haven't really changed the emailing system (the err function in BasicDB), so I should be getting emails -- but neither my emails nor my registration emails are coming through. I did change hosts since the last working version, but I wouldn't expect that to effect why the emails are causing server issues instead of being sent out. Again, I really just don't know what is going on behind the scense. I have been all over this code, debugging it through messages returned in javascript alerts at one point =) (for the errors returned from the ajax-called php).

I am the programmer for this code, though -- I wrote every line and commented it all. The problem is I fear to test it anymore lest my admin suspend my account, I have no idea what causes a core dump, and I can't get to my debugging messages.

I would really appreciate some help if anyone has a chance.


Attached are the four files. For easier use, I deleted most of the tabs that aligned the comments (as is seen in the code pasted above). If anyone wants them, I have the files with the comments aligned on the right with tab=4 in Notepad2.
I didn't see what happens to the obj after it is used - is it or could it be destroyed
or moved?
Mar 5 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4577
by: Manu J | last post by:
Hi, i have a login script which makes use of sessions. Login script *********** session_start() ..... ..... ....
1
14147
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10." The PERL code is as follows:
0
1168
by: Howard Kaikow | last post by:
Requiring a Passport account to register software is an unnecessary complication. I have tried using several passport accounts. When I then try to register .net 2003, I enter the passport login and I am then asked to login a second time, and then again and again. I've even been given the opportunity to change the password, then login again.
18
3391
by: Gleep | last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this. The goal I don't want clients to give out their usernames and passwords to friends, since the site relies on subscrption fees. Sessions ID's are matched between the browser and the server. So a users can login with same username and password and those sessions are tracked individually. Some suggest create table fields with the session ID...
9
3592
by: Ben | last post by:
Hello, I'll bet this has been asked a million times but I can't seem to find a thread that gives the clear example I need. This PC has MySQL and IIS configured and running. The MySQL database is "myDB" with a table "myUsers" with fields "Username" and "Password". I also have the MySQL ODBC driver loaded with a DSN "dsnMySQL" setup. First question is can someone direct me to a site or provide a sample code for a login page that...
2
1842
by: raknin | last post by:
Hi, I am looking for a close package of secure login and registeration written in PHP.The package that I am looking for should have the following functionality I believe this is standard functionality today: Login: 1. User enter user name and passsword 2. Forgot your password 3. Remember me on this computer
1
4363
George Lft
by: George Lft | last post by:
ok, first of all, i built my register page using dreamweaver tool which the codes haven been out of control. Now i'm thinking that turning over everything - by using this another set of codes. And these new sets of codes have overwhelmed me a bit. Here's the new code: CREATE TABLE `users` ( `ID` int(11) NOT NULL auto_increment, `Username` varchar(255) NOT NULL, `Password` varchar(255) NOT NULL, `Temp_pass` varchar(55)...
2
1783
by: =?Utf-8?B?d2R1ZGVr?= | last post by:
I have a website using windows integrated security, with anonymous access turned off. The site is used to query orders from a database and when the search takes a long time, a windows login box appears. Regardless of what login the user enters into this, it does not accept it and the user is locked out of the system. Our network team and myself have been unable to find out why this is occurring, has anyone else had a similiar problem?...
4
3782
by: Brett | last post by:
I have an ASP.NET 2.0 application that uses Forms Authentication. The startup page contains just a login control, and the site works well on an IIS 6 web server. I am now setting the site up on the production web server, which runs Windows 2008 Server and IIS 7. The login page comes up, but when I try to log in, I get the error, "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection." For debugging...
0
8649
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
9232
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
8936
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...
0
7827
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6573
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
5905
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
4411
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...
1
3104
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
3
2036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.