Skip to content

Instantly share code, notes, and snippets.

@yano3nora
Last active July 1, 2017 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yano3nora/cbb9a024a96b06593594cc169d7cd0da to your computer and use it in GitHub Desktop.
Save yano3nora/cbb9a024a96b06593594cc169d7cd0da to your computer and use it in GitHub Desktop.
[php: UA switch] attention on old code. #php
<php
/**
* UA switch ( pc / sp )
* <a href="hoge/index?ua=pc">DESKTOP</a>
* <a href="hoge/index?ua=sp">MOBILE</a>
*/
if (isset($_GET['ua'])) $_SESSION['ua'] = $_GET['ua'];
if (isset($_SESSION['ua'])) {
if($_SESSION['ua'] === "sp"){
// sp render
}elseif($_SESSION['ua'] === "pc"){
// pc render
}
} else {
$ua = $_SERVER['HTTP_USER_AGENT'];
if (
(strpos($ua,'iPhone')!==false) ||
(strpos($ua,'iPod')!==false) ||
(strpos($ua,'Android')!==false) ||
(strpos($ua,'Mobile')!==false) ||
(strpos($ua,'iPad')!==false)
) {
$_SESSION['ua'] = 'sp';
} else {
$_SESSION['ua'] = 'sp';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment