"not working" is useless information. Of course it's "not working," after all, why would you be asking for help if it
was working?
Instead, tell us:
1. What did you expect to happen?
2. What actually happened?
3. What have you done to try and figure out why (or even, what's your guess at what went wrong)?
That might indicate some difference in configuration between the servers - in their error handling, or in how they set their environment vars ($_SERVER, etc.). Did you get any error messages? Did you use the same browser to test in both cases?
On a related note, if you haven't already, I'd highly recommend checking with your web host before implementing any analytics code.
Many hosts:
-- prohibit data gathering for analytics, especially when using a database (because it's often expensive in processing terms)
-- have existing analytics tools, which are probably better than anything you might build yourself.
1. Do you have a defined constant named
getUserIpAddr
? Or are you actually trying to call your function (i.e.,
getUserIpAddr()
)?
2.
You should never insert user-provided data (your POST var, in this case, but this also includes any SERVER vars that start with "HTTP_...") directly into the database.
Best Case, SQL errors and confusing script crashes.
Worst Case, SQL Injection Attacks.
You need to sanitize your data by using the appropriate escape functions (e.g., mysql_real_escape_string()
- however, see #3 below.)
3.
If at all possible, you should avoid using the mysql_* functions.
ext/mysql is severely outdated and scheduled for deprecation. It is no longer recommended for new projects, and existing code should be updated to avoid performance and security problems. Using
ext/mysqli or the
PDO class is recommended. Read more about
choosing an API here.
Bookmarks