Archive for 'php'
[PHP] Aggiungere Post correlati Wordpress senza utilizzare alcun plugin!
Posted on 12. Mar, 2010 by daniele.
Per aggiungere post correlati nel vostro blog, copiate e incollate questo codice PHP nella pagina "single.php".
< ?php $original_post = $post; $tags = wp_get_post_tags($post->ID); if($tags) { echo ' <h4 class="content-title">Related Posts</h4> '; $sendTags = array(); foreach($tags as $tag) $sendTags[] = $tag->term_id; $args = array( 'tag__in' => $sendTags, 'post__not_in' => array($post->ID), 'showposts' => 5, 'caller_get_posts' => 1, ); $queryDb = new WP_Query($args); if($queryDb->have_posts()) { echo ' <ul>'; while ($queryDb->have_posts()) { $queryDb->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="< ?php the_title_attribute(); ?>"> < ?php the_title(); ?></a></li> < ?php } echo '</ul> '; } } $post = $original_post; wp_reset_query(); ?> </ul>
Continue Reading
Installare le librerie CURL con xampp!
Posted on 26. Feb, 2010 by daniele.
Nel file php.ini sostituite:
;extension=php_curl.dll
in
extension=php_curl.dll
Riavviate apache e il gioco è fatto
Continue Reading
Costruzione di un client REST con chiamate asincrone utilizzando PHP e curl!
Posted on 25. Feb, 2010 by daniele.
In questo tutorial creeremo una semplice interfaccia per chiamare webservices REST in PHP.
private function _run() { $headers = $this->_headers; $curly = $result = array(); $mh = curl_multi_init(); foreach ($this->_requests as $id => $reg) { $curly[$id] = curl_init(); $type = $reg[0]; $url = $reg[1]; $params = $reg[2]; if(!is_null($this->_user)){ curl_setopt($curly[$id], CURLOPT_USERPWD, $this->_user.':'.$this->_pass); } switch ($type) { case self::DELETE: curl_setopt($curly[$id], CURLOPT_URL, $url . '?' . http_build_query($params)); curl_setopt($curly[$id], CURLOPT_CUSTOMREQUEST, self::DELETE); break; case self::POST: curl_setopt($curly[$id], CURLOPT_URL, $url); curl_setopt($curly[$id], CURLOPT_POST, true); curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $params); break; case self::GET: curl_setopt($curly[$id], CURLOPT_URL, $url . '?' . http_build_query($params)); break; } curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, true); curl_setopt($curly[$id], CURLOPT_HTTPHEADER, $headers); curl_multi_add_handle($mh, $curly[$id]); } $running = null; do { curl_multi_exec($mh, $running); sleep(0.2); } while($running > 0); foreach($curly as $id => $c) { $status = curl_getinfo($c, CURLINFO_HTTP_CODE); switch ($status) { case self::HTTP_OK: case self::HTTP_CREATED: case self::HTTP_ACEPTED: $result[$id] = curl_multi_getcontent($c); break; default: if (!$this->_silentMode) { $result[$id] = new Http_Multiple_Error($status, $type, $url, $params); } } curl_multi_remove_handle($mh, $c); } curl_multi_close($mh); return $result;…
Continue Reading
Recuperare le informazioni del file caricato con PHP!
Posted on 24. Feb, 2010 by daniele.
In questo tutorial imparerete come ottenere le informazioni di un file attraverso l'array "$_FILES".
Continue Reading
[PHP] Trovare la posizione geografica di un utente!
Posted on 22. Feb, 2010 by daniele.
Grazie a questo semplice tutorial PHP, imparerete come trovare la posizione geografica di un utente.
Per prima cosa dovete scaricare il Database degli IP: Download
FILE import.php
< ?php // Connect to your database $con = mysql_connect("localhost", "yourUsername", "yourPassword"); // Display an error if there was a problem with connection if(!$con){ die(mysql_error()); } // Select your database $select_db = mysql_select_db("ip", $con); // If there was problems with selecting your database.. It will display an error if(!$select_db){ die(mysql_error()); } // Select your database file $db = file("ip-to-country.csv"); // Now let's get all rows separately and insert it into database foreach($db as $row){ $content = trim( str_replace('"', "'", str_replace("'", "\'", $row) ) ); $sql = "INSERT INTO locations (from, to, short, cc3, cname) VALUES($content)";…
Continue Reading
[PHP] Inviare post Twitter dalle vostre pagine!
Posted on 21. Feb, 2010 by daniele.
FORM HTML
<form id="tweet" name="tweet" method="post" action="tweet.php"> <textarea name="tweet-msg" rows="5" cols="50"></textarea> <input name="submit" type="submit" value="Tweet it" /> </form>
FILE PHP
$data = $_POST['tweet-msg']; $twitter_data = "status=" . substr($data, 0, 136) ." ..."; $twitter_user = 'tuauser'; $twitter_password = 'tuapassword'; $twitter_api_url = "http://twitter.com/statuses/update.xml"; $ch = curl_init($twitter_api_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $twitter_data); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERPWD, "{$twitter_user}:{$twitter_password}"); $twitter_data = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);
Continue Reading
Generare scelte casuali con PHP
Posted on 20. Feb, 2010 by daniele.
In questo tutorial imparerete come generare scelte casuali con PHP!
<html> <head> <script type="text/javascript"> function Add() { var Space = document.getElementById('extra'); Space.innerHTML += ' <input type="text" name="choice[]" value="" class="input" />'; } </script> <title>Cueburst - Random Choice Generator</title> </head> <body> <center> <div class="container"> <h2>Random Choice Generator</h2> < ?php $form = ' <strong>Stuck with a decision? Let me help! <a href="javascript:Add();">+</a> <center> <form action="choices.php" class="form" method="post"> <input type="text" name="choice[]" value="" class="input" /> <input type="text" name="choice[]" value="" class="input" /> <input type="text" name="choice[]" value="" class="input" /> <div id="extra" name="extra"></div> <input type="submit" name="submit" value="submit" /> </form> </center> '; if(!isset($_POST['submit'])) { echo $form; } else { $choice = $_POST['choice']; foreach($choice AS $number => $input) { if($input == null) { unset($choice[$number]); } } if(count($choice) == 0) { echo '<strong>Quack!</strong>No choices to choose…

