Tag "URL" (4)
Determination of the country by IP using geoplugin.net OR ipinfodb.com. Will return the country code in "Alpha-2 ISO 3166-1" format (a two-char code) ... Reveal Code
function get_country($ip_addr) {
$curlopt_useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0';
$url = 'http://www.geoplugin.net/php.gp?ip=' . $ip_addr;
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch1);
$geoplugin = unserialize($result);
if ($geoplugin[geoplugin_countryCode] != '') {
return $geoplugin[geoplugin_countryCode];
} else {
$url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip_addr);
$ch = curl_init();
$curl_opt = array(
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => $curlopt_useragent,
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 1,
CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
);
curl_setopt_array($ch, $curl_opt);
$content = curl_exec($ch);
if (!is_null($curl_info)) {
$curl_info = curl_getinfo($ch);
}
curl_close($ch);
if (preg_match('{
Country : ([^<]*)}i', $content, $regs))
$country = $regs[1];
return $country;
}
}
Rewrite URLs with .htaccess. If you use it then URL like "http://mydomain.com/user.php?show=JohnDoe" will be equivalent to "http://mydomain.com/JohnDoe/". ... Reveal Code
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+user\.php\?show=([^\s]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /user.php?show=$1 [L,QSA,NC]
htaccess: Rewrite URLs
Rewrite URLs with .htaccess. If you use it then URL like "http://mydomain.com/user.php?show=JohnDoe" will be equivalent to "http://mydomain.com/user/JohnDoe/". ... Reveal Code
RewriteEngine on
RewriteRule ^user/([-a-zA-Z0-9_]+)/? user.php?&show=$1 [L]
PHP: Make a clickable text
Make a clickable text: replace all the URLs with tag ... Reveal Code
function makeClickable($text) {
$text = preg_replace("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2$3", $text);
$text = preg_replace("/(^|[\n ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2$3", $text);
$text = preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1$2@$3", $text);
return($text);
}
Custom social sharing URLs for the most popular social networks ... Reveal Code
$facebook_link = "http://www.facebook.com/sharer.php?u=" . urlencode($URL) . "&t=" . urlencode($TITLE) . "&src=sp";
$twitter_link = "http://twitter.com/home/?status=" . urlencode($URL . " - " . $TITLE);
$googleplus_link = "https://plusone.google.com/_/+1/confirm?hl=en&url=" . urlencode($URL);
$reddit_link = "http://reddit.com/submit?url=" . urlencode($URL) . "&title=" . urlencode($TITLE);
$vkontakte_link = "http://vkontakte.ru/share.php?url=" . urlencode($URL) . "&title=" . urlencode($TITLE);