views:

17

answers:

1

Hi Everyone,

I have a simple PHP script that sends a message to a specified email address with content from a HTML form using the mail() function (which I am aware is prone to spam).

I was wondering if it's possible to obtain additional information about the user's settings and input them in the sent mail.

Additional information could contain:

  • Browser type and version Whether
  • Javascript is enabled or disabled
  • Operating system Resolution

If any of those are possible, that would be awesome.

Thanks, Amit

EDIT: Thanks to @Stephen, I was able to use the $_SERVER['HTTP_USER_AGENT'] to get more info regarding the browser. However, when using the get_browser, it did not work. This is my code:

$browser = get_browser(null, true);

$message = 'From: ' . "\n\n" . 
'Name: ' . $_REQUEST['name'] . "\n\n" . 
'E-mail: ' . $_REQUEST['email'] . "\n\n" . 
'Comments: ' . $_REQUEST['comments'] . "\n\n" . 
'Details: ' . $_SERVER['HTTP_USER_AGENT'] . "\n\n" . 
'Further: ' . echo ($browser);

Anyone knows the reason why?

Thanks!

+2  A: 

Many details can be found by parsing the $_SERVER['HTTP_USER_AGENT'] variable. Example for my current computer is:

echo $_SERVER['HTTP_USER_AGENT']
// Output: "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"

Remember that the contents of this are not a definite sign - browsers can and do (sometimes deliberately, sometimes accidentally) lie about their origins.

Note there are some functions like get_browser which wrap the HTTP_USER_AGENT to return some useful information too.

Stephen
This is great. Exactly what I wanted. Now, the get_browser looks like it should give a lot more info. However, it's not working for me. Could you take a look at my edit and let me know if you see a problem with it?
Amit
One sidenote though : get_browser will not detect whether a visitor currently has javascript et al enabled, it will just return whether the browser supports javascript. To detect if javascript is enabled just set an extra form field using javascript on submit, then you actually know javascript is enabled :p.
wimvds
See the note (on http://php.net/manual/en/function.get-browser.php) : In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system.
wimvds
I see. How exactly would you go about doing that?
Amit
@wimvds: Thanks again
Amit
@Amit - did you get the browscap working?
Stephen
@Stephen: I didn't -- gave up on it. Trying to understand the browscap was beyond me. For now, the HTTP_USER_AGENT is good enough for me.
Amit
@Amit - you want this [file](http://browsers.garykeith.com/stream.asp?PHP_BrowsCapINI). As far as I know, it's just a big blob of information about browsers to let get_browser accurately work out what it's dealing with. Personally I would just parse HTTP_USER_AGENT too...
Stephen
@Stephen - Yeah I'll just stick to the user_agent. I did see that file when I was looking around, and I took a look in it. I really had no idea what I'm supposed to do with it, whether I was supposed to upload it to my site's root folder, or what have you. Anyway, thanks for all of your help.
Amit
@Amit - Yes, you need to upload the ini file to somewhere on your system, then in your php.ini file you need to set the `browscap` property to the location of that file. Php.ini is usually located in your PHP's root folder - I use xampp so it's C:\xampp\php. Search for browscap in that file and it should have an example location for you to place the browscap.ini file at.
Stephen
@Stephen - I see. I use xampp as well, however I have a website which doesn't give me access to PHP and the www root folder...Oh well
Amit