PHP - Debugging Strategies
I am just starting my first solo web project in a new language (php) and since I don't have my old boss to go to for code help I need to build a stronger set of debugging strategies or at least a set of debugging strategies that goes beyond echo $varthatmightbegivingmetrouble .
Right now I'm working with this line of code right he $query = sprintf("INSERT INTO Users (UserName, Password) VALUES ('%s', '%s')", mysql_real_escape_string($UserName), mysql_real_escape_string($Password)); echo $query; which is outputting: "INSERT INTO Users (UserName, Password) VALUES ('', '')monkeykoder" Any help would be greatly appreciated. Similar TutorialsI have done lots of research on this, and I am trying out numerous method to counter this, which includes using mail() function with various arguments for the header, the PHPMailer class libraries and including a TXT file in my DNS settings with Godaddy. as far as mail() is concerned, I have this code: if( empty($errors)) { $to = '$myemail'; $email_subject = "Customer Contact Request Submitted"; $email_body = "A potential customer has sent you their contact information:\r\n\r\n" . "Name: " . $firstname . " " . $lastname . "\r\n" . "Email: ". $email . "\r\n" . "Phone: " . $phone . "\r\n" . "Products Interested In: " . $products_interested_in . "\r\n" . "Message: " . $message; $headers = "From: no-reply@domain.com\r\nReply-To: $email\r\nReturn-Path: $email\r\n"; mail($myemail, $email_subject, $email_body, $headers); echo "Your contact information has been sent. A respresentative will contact you shortly."; } else { echo $errors; } and the message is sent fine, but gmail spams it out every time it's sent regardless of whether it is marked as "not spam" and moved to the inbox. I have not read anything on what can be put in the header argument to try and prevent the spamming out. thoughts anyone? Secondly, I have not yet written the code to call PHPMailer class libraries, but all the experts say it is the most reliable way to send mail. Is PHPMailer messages known to be spammed out too? Thirdly, the TXT file I put in my DNS reads the following, per response #2 on this page: https://stackoverflow.com/questions/43241773/prevent-php-mail-sent-going-to-spam-gmail Type: TXT Host: mydomain.com Value: v=spf1 ip4:myIPaddressHere ~all TTL: Automatic (Godaddy's option for Automatic is "1 hour") I have to wait another 24 hours to see if that will fix the spamming issue. Godaddy requires 48 hours for their server to adopt the new settings. Does this look right to you guys as well? thanks. I'm getting a '500 Internal Server' and 'Premature end of script headers..' errors in the process of uploading a file. This occurs consistently with files > 2MB but also (very occasionally) w/ smaller files. The target directories are beneath the web root folder, so I don't think it's a permissions issue. I've set the following in my php5.ini: post_max_size = 8M, upload_max_filesize = 8M max_input_time = 360 max_execution_time = 360 Trace code/logging reveals that the error occurs even before my upload code is entered (which uses (move_uploaded_file()). So what would cause that? Any suggestions on how to debug this are very much appreciated! I'm new to php and having some trouble with debugging a piece of code. Could someone please help me understand what's the error. I'm using Code Lobster for debugging and attempting to validate input for a simple sign in form. The error is and code is shown below. If I can understand this, I think I can continue with the rest of the checking. Parse error: syntax error, unexpected T_FOREACH, expecting ')' in C:\wamp\www\login_check_blank.php on line 20 <php // Program name - login_check_Blank.php // Description - checks form for blank fields // Date - 10/26/10 // Programer - R. Langevin ?> <html> <head> <title>Checking for empty fields</title> </head> <body> <?php // set up array for all fields $labels = array( "userName" => "username", "passWord" => "password", // Check each field for blanks foreach ($_POST as $field => $value) { } if ($value =="") { $blank_array[] = $field; } // end of foreach loop for $_post // if any fields were blank, display error message and redisplay form if (@sizeof ($blank_array) >0 { echo "<strong>One or more requied fields were found to be blank</strong>" // display list of blank fields foreach($blank_array as $value) { echo " $nbsp; {$labels[$value] } <br>"; } } echo "$userName "welcome back to the Taft Union High School class of 65 website." exit() ?> </body> </html> folks, i know i may be asking a question that has been answered before but i am asking this here again because i could not find any simple and straightforward answers. i want to debug my php scripts. no web server is involved. all the scripts are used for parsing and preparing data files...something like we do with unix shell scripting. the scripts reside on a linux box and each script may call functions in other included scripts. i can connect to the linux box using my notebook. on my notebook i have Eclipse and PhpEd. i want to debug those php scripts on the linux box using my notebook's Eclipse or PhpEd. (no webserver or html involved and php cli is already setup and running scripts on the linux box). If this (using PhpEd and Eclipse on the notebook to remotely debug) is not possible can you please suggest me how do i debug those scripts while i am on the linux server (using command line etc.). please help me how to set up. regards, kali I'm a beginner. I should debug my code from the webserver. When i use arrays and get some error, i generally make "var_dump" or "print_r" to check my data contents. Most of the time, by echo'ing, i can get the errors with related to structure of arrays etc. But when dumped file is too big, webserver crashes. I use shared hosting, so it becomes problem. For example Code: [Select] $html = file_get_html( 'http://www.example.com' ); var_dump($html);I suppose, PHP runs it very long and reserved memory, RAM etc. becomes exhausted. To solve this i sometime write the outputs to txt files. But it would be handy to check the results from browser. What can you recommend me to not to crash server? Thank you Hi Guys, I am learning PHP via Netbeans IDE in LinuxMint because it just feels closer to Visual Studio which I used in the past, i am trying to lean more with open source technologies. I spin up a VirtualBox and installed apache2 on ubuntu. I created the netbeans project from my linuxMint to the virtualbox apache2 server (remote server) and configured the virtual directories on the apache2 server. I can the test project successfully, however I cannot seem to debug via Netbeans like toggling a breakpoint to view variable values. I found on the internet i need to configure xdebug and followed this site and used this page https://xdebug.org/wizard.php to create and install my xdebug. I then updated my php.ini file to the following:
[xDebug]
While my netbeans session id is configured "netbeans-xdebug" and debugger port to 9000. However, when i set a breakpoint in my code, netbeans seems to be stuck on "Waiting for connection" even it already passed the breakpoint. I suspect it's not even connected at all. I do see from my host laptop (where I am running netbeans) that port 9000 does open when running the project with debug and ufw is turned off in both virtualbox machine and laptop.
Any ideas? Hey all, I'm having some trouble running some mysql statements through mysqli. I've tried to debug them various ways, but to no avail. This is the offending code: class DBOPS { protected $config, $mysqli; public function __construct () { $this->config = array (...snip...); $this->mysqli = new mysqli ($this->config['server'], $this->config['username'], $this->config['password'], $this->config['database']); session_start(); } public function Login ($username, $password) { $toreturn = NULL; //Problem area is from here... $encryptedpassword = hash(...snip...); print_r(array( $this->config['usertable']['username'], $username, $this->config['usertable']['password'], $encryptedpassword)); $statement = $this->mysqli->stmt_init(); $statement->prepare('SELECT * FROM users WHERE ? = ? AND ? = ?'); $statement->bind_param( 'ssss', $this->config['usertable']['username'], $username, $this->config['usertable']['password'], $encryptedpassword); $statement->execute(); print_r($statement->affected_rows); //To here. if ($statement->affected_rows == 1) { $_SESSION[$this->config['sessiondata']['username']] = $username; $_SESSION[$this->config['sessiondata']['lastactivity']] = time(); $toreturn = TRUE; } else { $toreturn = FALSE; } $statement->close(); return $toreturn; } The print_r($statement->affected_rows); statement always returns -1, which means a query error. Is there a problem with the syntax of the predefined query in $statement->prepare('SELECT * FROM users WHERE ? = ? AND ? = ?') ? I really can't seem to find the problem in this code. There are no errors returned. The output from the print_r() statements are Code: [Select] Array ( [0] => Name [1] => Trey [2] => Password [3] => ...snip... )from the first print_r and Code: [Select] -1from the second. And lastly, I know that DIY login systems are generally discouraged, but this is more of a research project. I would greatly appreciate any help with this. Thanks. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=322069.0 |