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)
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 :
At 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:
Now 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:
At 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.
Well 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).