What
version of the reCAPTCHA lib are you using?
Connections to port 80 on most servers is blocked due to abuse. You could petition an admin to open port 80 for the reCAPTCHA server, which is
www.google.com. There are two potential issues with this: a social and a technical one. The former is that it will open up the Google servers for other uses, including potential abuse. The technical issue is that the domain resolves to any one of a number of IP addresses on many different subnets. Firewall rules are generally based on IP addresses rather than domain names since they are enforced at a lower level (the
link layer, while domain names are a part of the application layer). Mitigating the technical issue is that typically the domain will only resolve to a single subnet for DNS requests from client IPs in a given subnet (basically, a subnet of clients is generally assigned to a single subnet of Google servers). Also, an internal X10 DNS server could be used to further limit the addresses used by the X10 web servers themselves.
Code
indentation should be consistent, for the sake of readability.
Use
isset() or
empty to test whether a variable or array item is defined, so that your code will work when
notices are enabled.
PHP Code:
if (! empty($_POST["fb"])) {
The sample code is vulnerable to
SQL injection, which is a very serious
security risk. To fix this hole, switch from the outdated
mysql extension to
PDO and use
prepared statements. If you need a PDO tutorial, try "
Writing MySQL Scripts with PHP and PDO". The site you save may just be your own.
Don't use SELECT *; select only the columns you need.
You only need a loop if you're fetching more than one value. Drop the
while and use just a fetch. To simplify things even more, use
PDOStatement::fetchColumn.
To get the generated ID from the
INSERT statement, use
LAST_INSERT_ID(). For one thing, the current implementation will sometimes fail when the server is handling multiple page requests, when the
INSERT from one request comes between the
INSERT and
SELECT for another request.
PHP Code:
$lastIdQuery = $db->query('SELECT LAST_INSERT_ID()');
$id = $lastIdQuery->fetchColumn();
You should post
complete, concise sample code. For common libraries, post a link to the relevant library or (if the source is available on the web) to the source itself. For example:
recaptcha_check_answer
Don't use die when outputting HTML. You'll get invalid HTML.
<script> elements must be placed within the <head> or <body> of the document.
Moreover, you should be using an HTTP redirect rather than JS, which you can do with
header(). For one thing, not everyone has JS enabled or is using a JS-enabled browser; you should always consider
accessibility.
On the topic of accessibility, the textarea in the form could use a corresponding <label>.