I would like to create an icon for my website when user visits my website from mobile. I assume i will have to check the OS which request the url and on knowing from where the request came ie Apple, Android or Blackberry phones and executing script which will create icon if accepted by user..
Can this be done ? If yes, then how ?
Check the code below this will work
<?php
$ismobile = 0;
$container = $_SERVER['HTTP_USER_AGENT'];
// Mobile Company And Os
$useragents = array ('Blazer','Palm','Handspring','Nokia','Kyocera','Samsung','Motorola','Smartphone','Windows CE','Blackberry','WAP','SonyEricsson','PlayStation Portable','LG','MMP','OPWV','Symbian','EPOC','android','Android');
foreach ( $useragents as $useragents )
{
if(strstr($container,$useragents))
{
$ismobile = 1;
$browser = $useragents;
}
}
if ( $ismobile == 1 )
{
echo "<p>Browsing Using ".$browser." device</p>";
}
?>
And The Out Put Will Be Like Below
Browsing Using Android device
Related
My website is nearly ready to be released - an online game. One of the final problems I am facing is that the login form does not seem to be working on Google Chrome on MOBILE only. The website and form work perfectly on the Edge browser on mobile, and it also works perfectly on Chrome and all other browsers on PC - it's just Google Chrome on mobile for some reason. It's important as users of the game will need mobile access as I believe that it's the way forward.
I imagine it's something to do with cookies/cache - despite flushing the cache on mobile and enabling cookies, it still doesn't seem to work. Below is the script I am using - can anyone help!?
<?php
define('BASEPATH', true);
require('system/config.php');
if($_GET['e'] != '' && is_numeric($_GET['e'])){$ref_id = $db->EscapeString($_GET['e']); $_SESSION['NGRefCookie'] = $ref_id;}elseif(isset($_SESSION['NGRefCookie'])){$ref_id = $_SESSION['NGRefCookie'];}else{$ref_id = 0;}
if($config['affiliate_module']){
if(!empty($_GET['aff']) && is_numeric($_GET['aff'])){
$aff_id = $db->EscapeString($_GET['aff']);
$_SESSION['NGACookie'] = $aff_id;
}elseif(isset($_SESSION['NGACookie'])){
$aff_id = $_SESSION['NGACookie'];
}else{
$aff_id = 0;
}
}
$orign = empty($_GET['orign']) ? '/game/?side=startside' : $_GET['orign'];
if (IS_ONLINE)
{
header("Location: " . $orign);
exit;
}
$tSource = $_SERVER['HTTP_REFERER'];
if(!empty($tSource)){
$main_domain = parse_url($config['base_url']);
$http_referer = parse_url($tSource);
if($http_referer['host'] != $main_domain['host']){
setcookie('refSource', $db->EscapeString($tSource), time()+60*60*24, '/');
}
}
$sider = array(
'login' => 'login',
'signup' => 'signup',
'recover' => 'recover',
'contact' => 'contact'
);
$side = $sider[$_GET['side']];
if (isset($_COOKIE['MZ_Language']) && $languages_supported[$_COOKIE['MZ_Language']])
{
$langBase_lang = $_COOKIE['MZ_Language'];
}
if (isset($_GET['setLang']) && $languages_supported[$_GET['setLang']])
{
$lang = $languages_supported[$_GET['setLang']];
$langBase->language = $lang[0];
setcookie('MZ_Language', $langBase->language);
}
Thank you!
I'm currently doing a PHP script on a web app to scrap my drive :
By opening a PHP in my browser, I have a script based on examples provided by Google (https://github.com/google/google-api-php-client).
This script simply proceeds to a Files List and copy the files on the server.
It's working fine, but I want my Drive files to be synchronized with my server files. I have to run my PHP in my browser every time I want to copy again my files. Here are my questions about that :
Could I make a PHP script which would be executed programmatically by CRON everyday ?
At the moment the PHP opened in my browser needs an authentication (If no cookie of Google account already signed in is detected, I first need to login). I'd like to authorize my Google App once on my account to be able to scrap the drive every day.
Can I apply this script on multiple Google Accounts (Like having a list of G adresses or tokens, and the script runs for each one). The web app I'm doing is for a dizain of persons, and I'd like to synchronize their drives files with my server.
Thank you in advance for any answer. I don't know if this is very useful, but here is my code :
function retrieveAllFiles($service, $parameters) {
$results = array();
$pageToken = NULL;
do{
try {
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$files = $service->files->listFiles($parameters);
$results = array_merge($results, $files->getFiles());
$pageToken = $files->getNextPageToken();
} catch (Exception $e) {
print "Une erreur s'est produite : " . $e->getMessage();
$pageToken = NULL;
}
}while($pageToken);
return $results;
}
// Function to get a list of files id
function scrapDrive($service, $excluded) {
$final_files = array();
$query = "";
if(sizeof($excluded) == 0){
$query = "name = '--------'";
}else{
$query = "name = '".$excluded[0]."'";
}
// I just do a custom query if the user has chosen to exclude personal folders from his drive
foreach ($excluded as $folder_name) {
$query .= " or name ='".$folder_name."'";
}
// Get folders ID
$excluded_folders = retrieveAllFiles($service, array('q' => $query));
$excluded_folders_id = array();
foreach ($excluded_folders as $folder) {
array_push($excluded_folders_id, $folder['id']);
}
$usermail = getUserMail($service);
// Getting only files from last month
$artworks_query = "modifiedTime > '".date("Y-m-d\TH:i:sP",strtotime("-1 month"))."'";
// Only getting images
$artworks_query .= " and mimeType contains 'image/' and '".$usermail."' in owners";
foreach ($excluded_folders_id as $id) {
$artworks_query .= " and not '".$id."' in parents";
}
$artworks = retrieveAllFiles($service, array('q' => $artworks_query));
foreach ($artworks as $artwork) {
$final_artworks[$artwork['id']] = $artwork['name'];
}
return $final_artworks;
}
$excluded = getExcludedFolders($_SESSION['id']);
$artworks = scrapDrive($service, $excluded);
$nb_of_artworks = sizeof($artworks);
$i = 1;
// Copy each file
foreach ($artworks as $artwork_id => $artwork_name) {
$response = $service->files->get($artwork_id, array(
'alt' => 'media' ));
$content = $response->getBody()->getContents();
file_put_contents("folder/".$artwork_id.'_'.$artwork_name, $content);
}
$i++;
}
Thank you in advance for any help ! :-)
Could I make a PHP script which would be executed programmatically by CRON everyday?
Yes you can run a php script in cron. how to run a php script daily with the cron job on Ubuntu os
At the moment the PHP opened in my browser needs an authentication (If no cookie of Google account already signed in is detected, I first need to login).
That is because you are using Oauth2. You could just as easily save your refresh token in a file and then have your script read the refresh token from the file rather than reading it from the cookie. check this
I'd like to authorize my Google App once on my account to be able to scrap the drive every day.
If this is an account that you personally have control of then you should consider using service account authentication rather than Oauth2. check this
Can I apply this script on multiple Google Accounts (Like having a list of G adresses or tokens, and the script runs for each one). The web app I'm doing is for a dizain of persons, and I'd like to synchronize their drives files with my server.
Using Oauth2 you can have a refresh token for as many accounts as you wish. The owner of the account must simply authenticate your application and you will have a refresh token to access it.
I'm trying to get a little script working. It shouldn't be hard, but I'm kind of a n00b when it comes to PHP (my last experiments were many years ago).
So, basically, I want a little script that IF the client uses a mobile device, it gives a link to Facebook as an app link. IF the client has a regular laptop, the script should output a regular Facebook.
Okay, so I'm just going to show my screwed up code, to make it (hopefully) more clear what I'm trying (some might notice that I grabbed part of the code from another thread):
<?php
function check_user_agent ( $type = NULL ) {
$user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
if ( $type == 'mobile' ) {
if ( preg_match ( "/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent ) ) {
echo "fb://groups/334257489999204";
} else if ( preg_match ( "/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap /", $user_agent ) ) {
echo "fb://groups/123456789";
}
}
else {
echo "https://www.facebook.com/groups/123456789";
};
echo "https://www.facebook.com/groups/123456789";
};
?>" />
This code is in a html anchor href tag, inside a .php file (mainly HTML though).
Thanks!
This should set you on the right path
$user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
if ( empty($user_agent) ) {
$is_mobile = false;
} elseif ( preg_match ( "/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap|phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent ) ) {
$is_mobile = true;
} else {
$is_mobile = false;
}
echo (is_mobile) ? 'I am a mobile !' : 'I am not a mobile :(';
So I have a UIWebView in my app that loads a website I made. So it's loading web files not local files.
How can I make it so that this website cannot be viewable on any iPhone internet browsers, but can be viewable on my UIWebView.
Code for get browser deatils...
<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$browser = get_browser(null, true);
print_r($browser);
?>
Try this to check uiwebview,otheriOS browsers and not iOS browsers,
<div id="where-am-i"></div>
<script>
var standalone = window.navigator.standalone,
userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );
if( ios ) {
if ( !standalone && safari ) {
document.getElementById( 'where-am-i' ).textContent = 'browser';
} else if ( standalone && !safari ) {
document.getElementById( 'where-am-i' ).textContent = 'standalone';
} else if ( !standalone && !safari ) {
document.getElementById( 'where-am-i' ).textContent = 'uiwebview';
};
</script>
I'm trying to figure out the visitor's OS is either a Windows, Mac or Linux using PHP(I don't need the version, distro info.. etc). There's several methods out there however they look a bit too complicated for this simple requirement.
Are there any simple ways that could provide this sort of information yet still being quite reliable?
Thanks in advance.
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/Linux/',$agent)) $os = 'Linux';
elseif(preg_match('/Win/',$agent)) $os = 'Windows';
elseif(preg_match('/Mac/',$agent)) $os = 'Mac';
else $os = 'UnKnown';
echo $os;
?>
For an easy solution have a look here.
The user-agent header might reveal some OS information, but i wouldn't count on that.
For your use case i would do an ajax call using javascript from the client side to inform your server of the client's OS. And do it waterproof.
Here is an example.
Javascript (client side, browser detection + ajax call ):
window.addEvent('domready', function() {
if (BrowserDetect) {
var q_data = 'ajax=true&browser=' + BrowserDetect.browser + '&version=' + BrowserDetect.version + '&os=' + BrowserDetect.OS;
var query = 'record_browser.php'
var req = new Request.JSON({url: query, onComplete: setSelectWithJSON, data: q_data}).post();
}
});
PHP (server side):
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$session = session_id();
$user_id = isset($user_id) ? $user_id : 0;
$browser = isset($_POST['browser']) ? $_POST['browser'] : '';
$version = isset($_POST['version']) ? $_POST['version'] : '';
$os = isset($_POST['os']) ? $_POST['os'] : '';
// now do here whatever you like with this information
}
use the Net_UserAgent package
docu is here: http://pear.php.net/package/Net_UserAgent_Detect/docs/latest/Net_UserAgent/Net_UserAgent_Detect.html#methodgetOSString
get the php file here:
package/Net_UserAgent_Detect/docs/latest/__filesource/fsource_Net_UserAgent__Net_UserAgent_Detect-2.5.1Detect.php.html