SeaMonkey Browser – modify the UserAgent string

ATTENTION, please ! Playing with browser’s preferences may DAMAGE or ERASE your browser’s and email accounts and data ! So, it’s MANDATORY to create a backup of the user’s profile before starting the activity !

I need for a sort of “filter” to make “private” some PHP scripts on my website. I just want that such scripts will work only when accessed by my PC’s browser. My public IP changes very often (it’s dynamic) so can’t be used as a proof of a request coming from my PC. An easy way can be to add a personalized message to the usual UserAgent string of my browser. I use “SeaMonkey” ‘cause is very fast and “light” and also integrates the email client ; looking at the configuration options I didn’t found how to modify the UserAgent string, but googling for an answer I found that there is a preference that can be set to override the default one. The problem is that I don’t want just to override the “normal” UserAgent, but I just want to “append” my own string. So I created a very small PHP script just to know what’s my actual UserAgent. I called this script “UAget.php” ; it’s very simple, look at the picture below (note that clicking on the pictures loads 1:1 scale view)

The PHP script UAget.php

The PHP script UAget.php

I saved that script to an executable folder of my website (that can handle PHP scripts, obviously). Now, starting SeaMonkey and giving the URL of my script I had this result :

UAmod-pic1That’s my actual UserAgent. Well, I copied the whole string to the clipboard (ctrl-C) for future use.

UAmod-pic2At this point, I can try to add my personalized string to the UserAgent. For adding a new preference to the SeaMonkey’s configuration, you have to type “about:config” in the URL bar. You will receive an alert like this:

UAmod-pic3Don’t care about this, just click the button “I’ll be careful, etc” and go on…

UAmod-pic4Now you can see a list of option keys. Just click in empty space the right mouse key and on the descending menu choose: New, then: string and click for confirmation. You will be asked about the name of new preference:

UAmod-pic5The name will be: “general.useragent.override”, so write it down and click OK. Now a new box opens, requesting the string related to the new preference:

UAmod-pic6At this point, we paste (ctrl-V) the contents of the clipboard, that’s the original UserAgent string, and then append our personal string, in this example: ” Pippo/9.1.2015″, clicking OK to confirm. Look, our new “key” is part of the preferences list.

UAmod-pic7Ok, now we close the browser, then open it again and again we write the URL that points to our “UAget.php” script and this is the result:

UAmod-pic8Well done… our browser’s UserAgent, now, has an additional field: ” Pippo/9.1.2015″. This can be used in our PHP scripts to determine if the script itself will answer to requests or not, by means of parameter $_SERVER[‘HTTP_USER_AGENT’] used as filter. If the parameter contains our personalized string, then the script has been accessed by our browser (or by any other device that has ” Pippo/9.1.2015″ as part of the UserAgent).