Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone detection php

I have several Index.php files, such as (index.php, index2.php, index3.php etc.), I also have a database with different ID URL's. when some one enters a index file, the landing pages the see are dynamic and only the specified parameters in the database changes some of the parameters on display, lets say i enter domain.com/index.php?id=2 - this is for X city and the domain domain.com/index2.php?id=112 will display a page for Y city.

So far so Good..

now i am trying to insert a Iphone detection code, that will redirect users that are entering the urls from iphone to an iphone friendly design. so i created an i-index.php inserted the following code into the index.php page:

<?
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
{
  header('Location: http://www.mydomain.com/mobile/i-index.php');
  exit();
}
?>

and now when i enter the url mydomain.com/index.php?id=1 from my iphone i am redirected to the i-index.php file but not to the specified ID (?id=1).

i hope my explanation is not to confusing. can anyone suggest a way for it to redirect to the specified ID (both original index and the mobile index are connected to the database correctly)

Thank you

like image 286
orlyidd Avatar asked Jun 28 '26 13:06

orlyidd


1 Answers

<?
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
{
  header('Location: http://www.mydomain.com/mobile/i-index.php?id='.$_GET['id']);
  exit();
}
?>
like image 63
Menztrual Avatar answered Jun 30 '26 01:06

Menztrual



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!