Jyoti Sandhiya
Jyoti Sandhiya

Reputation: 173

Mobile Redirect using Resolution in PHP

I have 2 page

index.php (For Desktop)

and

indexm.php (For Mobile)

I want to redirect it with detection of screen resolution size.

I'm trying this code

<?php 
  if (screen.width <= 720) {
      include "indexm.php";
  } else {
      include "index.php";
  }
?>

But both the code is not working, Please help me with PHP Code to make it work.

Note : I'm not looking Header Location

header('Location: indexm.php');

Upvotes: 0

Views: 1371

Answers (3)

Jyoti Sandhiya
Jyoti Sandhiya

Reputation: 173

This Works!

<script type="text/javascript">
    if (screen.width <= 720) {
        window.location = "indexm.php";
    } else {
        window.location = "index.php";
    }
</script>

Upvotes: 0

uffix
uffix

Reputation: 1

this may solve your problem:

try this

<script type="text/javascript">

if (screen.width <= 720) {
document.location = "mobile.html";
}
</script>

Upvotes: 0

Kinjal Pathak
Kinjal Pathak

Reputation: 371

Since php is a server side language, it is not possible to detect screen resolution using php. You will have to use client side scripting to achieve the desired output.

Try the below javascript code

<script type="text/javascript">
    if(screen.width <= 720) 
    {
        location.href = "indexm.php"; // redirection
    }
    else
    {
        location.href = "index.php"; // redirection
    }
</script>

Upvotes: 3

Related Questions