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 addresses. when someone enters the index file, the landing pages are displayed dynamically, and only the specified parameters in the database change some of the displayed parameters, say, I enter domain.com/index.php?id=2 - this is for X and domain.com /index2.php?id=112 displays a page for city Y.

So far so good ..

now I am trying to insert an Iphone discovery code that will redirect users who enter URLs from iphone to iphone friendly design. so I created i-index.php, pasted 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 does not confuse. can anyone suggest a way to redirect the specified identifier (both the source index and the mobile index are correctly connected to the database)

thank

+3
source share
6 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();
}
?>
+2
source

so I created an inserted i-index.php

...

header ('Location: http://www.mydomain.com/mobile/i-index.php ');

So, if iphone requests i-index.php, then the script sends a redirect to i-index.php

?

not to the specified ID (? id = 1).

Where does he say "? Id = 1" in your code?

0
source
header('Location: http://www.mydomain.com/mobile/i-index.php?id='.$_GET['id']);
0

<?php

function isIphone($user_agent=NULL) {
    if(!isset($user_agent)) {
        $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
    }
    return (strpos($user_agent, 'iPhone') !== FALSE);
}

if(isIphone()) {
    header('Location: http://www.yourwebsite.com/phone');
    exit();
}

// ...THE REST OF YOUR CODE HERE

?>

javascript

var agent = navigator.userAgent;
var isIphone = ((agent.indexOf('iPhone') != -1) || (agent.userAgent.indexOf('iPod') != -1)) ;
if (isIphone) {
    window.location.href = 'http://www.yourwebsite.com/phone';
}

iPhone

0

i-index.php. , , , i-Phone. , index.php, .

<?

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

PHP, RewriteEngine .htaccess. :

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteCond %{REQUEST_URI} !^/mobile/i-index.php
RewriteRule .* /mobile/i-index.php [R,QSA]

QSA URL- .

.

0

All Articles