Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Sebastián http://www.envero.org

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Devuelve el Referer limpio

// Limpia y devuelve el REFERER

	function getReferer(){
		// limpia el referer 
		$ref = $_SERVER['HTTP_REFERER'];
		$web = str_replace(array('http://','www.'),'',$ref);
		$web = substr($web,0,strpos ($web, '/'));
		if(!empty($web)):
			// retorna el referer limpio
			return $web;
		else:
			// sin referer
			return 'jane.es';
		endif;
	}

recupera datos del visitante

	function getLocation( $ip ) {
		
		static $location = array();
		
		if( !isset( $location[$ip] ) ) {
			$url = "http://www.hostip.info/api/get.html?ip=" . $ip . "&position=true&raandom=" . rand(0,500);
			/* cURL */
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$data = curl_exec($ch);

			if ( curl_errno( $ch ) ) {
				print "Error: ".curl_error($ch);
			} else {
				curl_close($ch);
				$lines = split ("\n", $data);
				foreach($lines as $l):
					$prop = split(':',$l);
					$location[$ip][trim($prop[0])] = addslashes(trim($prop[1]));
				endforeach;
		   }
			
		}
		return $location[$ip];
	}
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS