IPhone detection
Wednesday, February 17th, 2010if (stristr($_SERVER['HTTP_USER_AGENT'], ‘iPhone’))
{
// redirect to an iphone version
}
if (stristr($_SERVER['HTTP_USER_AGENT'], ‘iPhone’))
{
// redirect to an iphone version
}
upload a single file to a FTP server
// FTP access parameters
$host = ‘ftp.myftp.com’;
$usr = ‘username’;
$pwd = ‘password’;
// file to move:
$local_file = ‘./example.txt’;
$ftp_path = ‘/data/example.txt’;
// connect to FTP server
$conn_id = ftp_connect($host, 21) or die (”Cannot connect to host”);
// send access parameters
ftp_login($conn_id, $usr, $pwd) or die(”Cannot login”);
// perform file upload
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);
// check upload status:
print (!$upload) ? ‘Cannot upload’ : ‘Upload complete’;
print “\n”;
/*
** Chmod the file (just as example)
*/
// If you are using PHP4 then you need to use this code:
// (because the “ftp_chmod” command is just available in PHP5+)
if (!function_exists(’ftp_chmod’)) {
function ftp_chmod($ftp_stream, $mode, $filename){
return ftp_site($ftp_stream, sprintf(’CHMOD %o %s’, $mode, $filename));
}
}
// try to chmod the new file to 666 (writeable)
if (ftp_chmod($conn_id, 0666, $ftp_path) !== false) {
print $ftp_path . ” chmoded successfully to 666\n”;
} else {
print “could not chmod $file\n”;
}
// close the FTP stream
ftp_close($conn_id);
US homeland threat level
<?php
/*
Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
This work is licensed under the Creative Commons Attribution License. To view
a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. */
// Obtain the current Department of Homeland Security threat level.
function getThreatLevel()
{
return eregi_replace(’.*CONDITION=”(.*)” />’, ‘\1′, file_get_contents(”http://www.dhs.gov/dhspublic/getAdvisoryCondition“));
}
echo getThreatLevel();
?>
This example shows how to use tinyurl’s api to genearte a short url from a url you pass, there are other services which offer this functionality
<?php
/**
* Use tinyurl to generate a short url
*
* @param string $url The url that you want to shorten
*/
function ShortUrl($url)
{
$tinyurl = file_get_contents(”http://tinyurl.com/api-create.php?url=”.$url);
return $tinyurl;
}
//usage example
echo ShortUrl(”http://www.getphp.net/a-google-pagerank-script/“);
?>
A google pagerank script
<?php
function page_rank($site)
{
$url = ‘http://google.com/search?client=navclient-auto&ch=6-1484155081&features=Rank&q=info:’;
$fp = fopen($url.’http://’.$site, ‘r’);
$content = fread($fp, 200000);
fclose($fp);
$rank = explode(’:',$content);
if($rank[2] != ”)
return $rank[2];
else
return FALSE;
break;
}
echo ‘Google Rank: ‘.page_rank(’getphp.net’);
?>