"OS detect and Redirect" is a simple script that detects the user's operating system (Desktop, Android, or iOS) and redirects them to a specific URL based on their OS. This can be especially useful for websites that want to guide users to platform-specific content or applications.
- Server-side detection using PHP.
- Client-side detection using JavaScript.
- Supports redirection for:
- Desktop (all platforms)
- Android (both mobile and tablet)
- iOS (both iPhone and iPad)
-
Clone this repository:
git clone https://github.com/AsifKibria/OS-detect-and-Redirect
-
Navigate to the project directory:
cd OS-detect-and-Redirect
-
Upload the PHP or HTML file (depending on which method you're using) to your server.
- Edit the
redirect.php
file. - Replace the placeholder URLs (
https://ios.example.com
,https://android.example.com
, andhttps://desktop.example.com
) with your desired redirection URLs. - Include or require the
redirect.php
at the beginning of your PHP script or use it as your landing page.
- Edit the
redirect.html
file. - Replace the placeholder URLs (
https://ios.example.com
,https://android.example.com
, andhttps://desktop.example.com
) with your desired redirection URLs. - Use the
redirect.html
as your landing page or embed the JavaScript section in your existing HTML file.
- The PHP method uses the
$_SERVER['HTTP_USER_AGENT']
variable to detect the user agent string and determine the user's OS. - The JavaScript method uses the
window.navigator.userAgent
property to achieve the same goal on the client side.
- The JavaScript method is client-side and will redirect the user after the initial page has started loading, which might not be as seamless as the PHP method.
- User agent strings can be spoofed, so this method is not 100% foolproof. However, for most general use cases, it should work effectively.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.