1

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');

Jyoti Sandhiya
  • 203
  • 2
  • 8

3 Answers3

2

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>
0

this may solve your problem:

try this

<script type="text/javascript">

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

This Works!

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