Help with displaying Errors in PHP
I have a routine I would like to streamline. Currently on my registration page you can either enter a key (returning user) or sign up. Once you fill out a form, the form is processed by a script on another server (includes some CRM database inserts so it has to be on the same server as the CRM) I am doing client side validation with jQuery, but the SS validation checks the license key to make sure its valid. If it is in valid it does the following - changes the URL to the processor URL, displays an alert with error message and returns you to the registration page. I hate this.
if (($row = mysql_fetch_assoc($result)))
{
header("Location: http://" . $redirect);
}
else
开发者_开发知识库 {
echo "<html>\n";
echo "<body>\n";
echo "<script language=\"Javascript\">\n";
echo "<!--\n";
echo "alert (\"The NinjaTrader license ID you entered was not correct.\");\n";
echo "window.location=\"http://www.dirtybirddesignlab.com/download-registration.php\";\n";
echo "//-->\n";
echo "</script>\n";
echo "</html>\n";
echo "</body>\n";
}
mysql_close($link);
}
I did not write this, and want to improve upon it. I would prefer it display a processing msg, make the check and if it is an invalid code, display that message above or in the form. Would this require cURL due to same origin policy/cross domain? I use cURL in several other areas but can't get this to work, i get errors relating to not closing the MySQL connection. Is there a simpler way to fix the above code to simply "print" to the page an error msg with out changing url and displaying alert? thanks experts!
Easiest, if possible, would be to eliminate the cross-domain problem by having the validator respond on a compatible subdomain (either by pointing a subdomain at it, or by using a reverse proxy on your own domain). The reverse proxy solution basically does what you're trying to do with cURL, except that it's faster to set up.
On the other hand, without AJAX, you could replace the error message and alert with:
header("Location: http://domain.com/download-registration.php?err");
And have the script detect ?err
and display the error message:
if (isset($_GET['err'])) echo "There was an error";
This takes the least work to do, but any data in the form will be lost.
精彩评论