-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.php
77 lines (67 loc) · 2.7 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
// Allows us to reset the cookie for testing purposes.
if(isset($_GET['reset'])){
setcookie ('resolution', '', time() - 3600, '/'); // Destroys cookie
header('Location: example.php?analysis');
exit;
}
// Temporary intermediary stage (for display purposes only)
// between resetting cookie and setting again, to make sure the cookie has really cleared.
if(isset($_GET['analysis'])){
echo '<h1>Cookies:</h1>';
echo '<pre>';
var_dump($_COOKIE);
echo '</pre>';
echo '<a href="example.php">View site fresh</a>';
exit;
}
// If user shows up and doesn't have a cookie set
if(!isset($_COOKIE['resolution'])) {
?>
<script>
// Set cookie based on screen size (from adaptive-images)
document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';
location.reload(true);
</script>
<?php
// If user doesn't have JavaScript, they'll just keep moving past here like nothing happened.
}
$res = !empty($_COOKIE['resolution']) ? $_COOKIE['resolution'] : 500; // Arbitrary mobile resolution.
echo '<div class="alert">STATUS: Resolution is set at '.$res.'px wide <a href="?reset" style="display: block; float: right;">Reset</a></div>';
?>
<!doctype html>
<!--[if lt IE 8]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
html { max-width: 1000px; margin: 0 auto;}
.alert { padding: .5em; background: #eee; border: 1px solid #ddd; }
</style>
</head>
<body>
<div id="container">
<header>
<h1>Content</h1>
<?php
if($res > 800) {
echo 'Showing desktop navigation. <a href="#" style="background: red; color: white; padding: 50px; display: block;">Go home</a>';
} else {
echo 'Showing mobile navigation. <a href="#" style="background: red; color: white; padding: 5px; display: block;">Go home</a>';
}
?>
</header>
<div id="main" role="main">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<footer>
</footer>
</div> <!--! end of #container -->
</body>
</html>