Hello, my name is alkarnur. I just started learning PHP a few months back and I'm really excited about it
I normally solve my own PHP problems, but most of the time, they're very basic, seeing as how I'm a beginner really.
I'm working on a personal site and there's a link that should be different when I visit my site using a specific OS, or a specific UserAgent, or a specific IP address.
So normally, the link points to site A, but if any of the above three conditions is true, it points to site B.
As an example: Normally, the link points to site A, but if I visit my site from a Mac (OS test), or an iPhone or iPad (UserAgent test), or from my home (IP test), I want it the link to be changed to point to site B.
I already did a somewhat extensive search but all I got was fragments and I'm not sure how to put them together.
Can anyone please help me?
If you'd like I can post the pieces of code I found in my search
I usually try to test for whether the positive conditions are true (because they may change later on) rather than try to work with negative conditions (i.e. "if it's not a mac or an ios it should be a windows or a linux"). That always somehow gets me in trouble.
I'm still open to suggestions, however, if anybody thinks there's something that can be improved with the script.
I'm still open to suggestions, however, if anybody thinks there's something that can be improved with the script.
Personally I wouldn't just drop it into the script like that. I'd have separate functions to do address- and user-agent-sniffing, and put them in a separate file so that the same code can be reused in different situations.
Also, unless you want the actual content of the page to be different depending on what the user agent claims to be (which is often frowned upon - Google for example will count it against you if you serve their spiders something different from what you serve everyone else), then there are often alternatives to UA-sniffing where the client itself can decide what is most appropriate (such as feature testing in JavaScript and media selectors in CSS).
Bookmarks