sabato 18 maggio 2013

Login with Facebook Php

Login with Facebook via PHP has never been so easy!The integration between Facebook and Php is often synonymous with Rogne and various problems.I will try to make you understand in the way more simple as possible how to achieve a page php which carries out the user's login on facebook and pulls out the credentials storing them into variables.
First of all download the SDK for PHP from here: https://github.com/facebook/facebook-php-sdk;Now create a file Accedi.php and copy the code below:
<?

//richiamo la facebook php sdk
require 'facebook-php-sdk-master/src/facebook.php';

//mi collego a facebook, sostituisco i parametri AppID e AppSecret con quelli della mia App
$app_id = 'xxxxxxxxxx';
$app_secret = 'xxxxxxxxx';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));

// Verifico se l'utente è connesso altrimenti lo collego
$user = $facebook->getUser();

//Controlla se l'utente è loggato su Facebook
if ($user) {
try {
   
// Cose da fare se l'utente è connesso
// Stampo informazioni dell'utente

$user_profile = $facebook->api('/me');

$first = $user_profile['first_name'];
echo "Benvenuto ";
echo $first;
echo " ";
$last = $user_profile['last_name'];
echo $last;
echo "<p>";

$FB_ID = $user_profile['id'];
echo "Il tuo Facebook ID e': ";
echo $FB_ID;
echo "<p>";

$FB_LINK = $user_profile['link'];
echo "Il tuo Facebook Link e': ";
echo $FB_LINK;
echo "<p>";

$compleanno = $user_profile['birthday'];
echo "Sei nato il: ";

$separatore="/";
$suddivisa=explode($separatore, $compleanno);
$mese=$suddivisa[0];
$giorno=$suddivisa[1];
$anno=$suddivisa[2];

echo $giorno;
echo"/";
echo $mese;
echo "/";
echo $anno;
echo "<p>";

$citta = $user_profile['location']['name'];

echo "Vivi a : ";
echo $citta;
echo "<p>";

$cittanatale = $user_profile['hometown']['name'];
if($cittanatale){
echo "Sei nato a : ";
echo $cittanatale;
echo "<p>";
}
$istruzione = $user_profile['education'][0]['school']['name'];
if($istruzione){
echo "Istruzione : ";
echo $istruzione;
echo "<p>";
}

$sesso = $user_profile['gender'];
echo "Sei: ";
if($sesso=="male"){
    $sesso="Maschio";
}
else if($sesso=="female"){
    $sesso="Femmina";
}
echo $sesso;
echo "<p>";

$lingua = $user_profile['locale'];
echo "Lingua: ";
$intermezzo="_";
$tokenlingua=explode($intermezzo, $lingua);
$lingua=$tokenlingua[1];
echo $lingua;
echo "<p>";

echo "<img src='http://graph.facebook.com/$FB_ID/picture'/>";

echo "<p>";

} catch (FacebookApiException $e) {
   
//se avviene qualche errore lo segnalo
error_log($e);
$user = null;
}
} else {
   
//se l'utente non è loggato faccio fare il login automatico
$params = array(
'scope' => 'user_birthday',
);
$loginUrl = $facebook->getLoginUrl($params);
echo("<script> top.location.href='" . $loginUrl . "'</script>");
}
?>

 
Replace the app id and app secret with those of your facebook app, copy the folder the SDK in the same directory where the file is located and you will Accedi.php concluded.When you open the page Accedi.php will ask you to log in with facebook and will print your personal data!

Getting Array of Facebook friends with Php

Are you trying to create an array containing Facebook friends and their information with php but it does not come out?
Here is the guide for you.
Download the SDK for PHP from here: https://github.com/facebook/facebook-php-sdk;
Create a file LettoreAmici.php and paste this into this:
<?
require 'facebook-php-sdk-master/src/facebook.php';
$ app_id = 'xxxxxxxxxxxxxx';
$ app_secret = 'xxxxxxxxxxxx';
$ facebook = new Facebook (array (
'AppId' => $ app_id,
'Secret' => $ app_secret,
));
$ user = $ facebook-> getUser ();
if ($ user) {
try {
$ user_profile = $ facebook-> api ('me / friends');
print_r ($ user_profile);
} Catch (FacebookApiException $ e) {
error_log ($ e);
$ user = null;
}
Else {}
$ params = array (
'Scope' => 'user_birthday',
);
$ loginUrl = $ facebook-> getLoginUrl ($ params);
echo ("<script> top.location.href = '". $ loginUrl. "' </ script>");
}
?>
Replace the lines $ app_id = 'xxxxxxxxxxxxxx', and $ app_secret = 'xxxxxxxxxxxx', with your app-secret and once started the page you will have the array with the information of your friends in the variable $ user_profile, which will also be printed in video from the command print_r.

Sending files via Socket Php

With php you can, just like with the java or c + + or any other language, implement tcp sockets for the exchange of data according to the client-server scheme.I show you how you can send a text file using a socket in php from a client to a server implementing only 2 files php: Server.php and Client.php.We start from the Server:

    
<? Php
    
set_time_limit (0);
    
if (($ sock = @ socket_create (AF_INET, SOCK_STREAM, SOL_TCP))) {
    
echo socket_strerror (socket_last_error ($ sock)); exit;
    
}
    
if ((@ socket_set_option ($ sock, SOL_SOCKET, SO_REUSEADDR, 1))) {echo socket_strerror (socket_last_error ($ sock));
    
exit;
    
}
    
if ((@ socket_bind ($ sock, '10 .0.1.4 ', 1048))) {/ / associate an ip of the machine and bring it to the socket
    
echo socket_strerror (socket_last_error ($ sock)); exit;
    
}
    
if ((@ socket_listen ($ sock))) {/ / put the listening socket
    
echo socket_strerror (socket_last_error ($ sock)); exit;
    
}
    
while (true) {
    
if (($ client = @ socket_accept ($ sock))) {/ / locking function: as long as it receives a request
    
echo socket_strerror (socket_last_error ($ sock));
    
exit;}
    
if ((@ socket_getpeername ($ client, $ addr))) {/ / we take the IP address of the client that is connected echo socket_strerror (socket_last_error ($ sock));
    
exit;
    
}
    
echo "Client connection from: $ addr \ n";
    
echo "Receiving file."
    
if (($ file = @ fopen ("." time ().. "txt", "w"))) {
    
echo "File open error. \ n"; exit;
    
}
    
if (($ rcv = @ socket_read ($ client, 1024, PHP_BINARY_READ))) {
    
echo socket_strerror (socket_last_error ($ sock));
    
exit;}
    
do {
    
if ((@ fwrite ($ file, $ rcv, 1024))) {
    
echo socket_strerror (socket_last_error ($ sock));
    
exit;}
    
if ((@ socket_write ($ client, "ok"))) {
    
echo socket_strerror (socket_last_error ($ sock));
    
exit;
    
}
    
if (($ rcv = @ socket_read ($ client, 1024, PHP_BINARY_READ))) {echo socket_strerror (socket_last_error ($ sock));
    
exit;
    
}
    
echo "."
    
} While ($ rcv! = "- @ END @ -");
    
echo "DONE \ n"; socket_close ($ client); break;
    
}
    
fclose ($ file);
    
socket_close ($ sock);
    
?>
And now the client:

    
<? Php
    
set_time_limit (0); / / Avoid that after a certain time the interpreter blocks php script as php.ini
    
if (($ file = @ fopen ("myfile.txt", "r"))) {
    
echo "File open error \ n."
    
exit;}
    
$ Server = array ('address' => 'Enter server ip', 'port' => 1048);
    
$ Sock = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);
    
if (($ connection = @ socket_connect ($ sock, $ server ['address'], $ server ['port']))) {echo socket_strerror (socket_last_error ($ sock));
    
exit;
    
}
    
echo "Uploading files."
    
do {
    
if (feof ($ file)) {
    
echo "send complete \ n"; socket_write ($ sock, "- @ END @ -"); break;
    
}
    
if (($ pkt = @ fread ($ file, 1024))) {
    
echo socket_strerror (socket_last_error ($ sock));
    
exit;}
    
if ((@ socket_write ($ sock, $ pkt, 1024))) {
    
echo socket_strerror (socket_last_error ($ sock)); exit;
    
}
    
echo "."
    
if (($ rcv = @ socket_read ($ sock, 1024))) {
    
echo socket_strerror (socket_last_error ($ sock)); exit;
    
}
    
/ / Echo $ rcv. "\ N";
    
} While (true);
    
echo "DONE \ n";
    
fclose ($ file); socket_close ($ sock); echo "Exiting ... \ n";
    
?>
First start the server socket and then the client socket and you will see that the file "myfile.txt" will be sent from the client to the server!

Post on Facebook wall with PHP

Here is a simple PHP page that takes care to publish a post on facebook through php.

Download the Facebook SDK for PHP from here: https://github.com/facebook/facebook-php-sdk;

Insert the SDK folder on your server.

Create a page called PostFacebook.php and stick the following code:

<? php
require 'facebook-php-sdk-master/src/facebook.php';
$ app_id = 'Your App ID';
$ app_secret = 'Your App Secret';
$ facebook = new Facebook (array (
'appId' => $ app_id,
'secret' => $ app_secret,
));


$ user = $ facebook-> getUser ();


if ($ user == 0) {

$ login_url = $ facebook-> getLoginUrl ($ params = array ('scope' => "publish_stream"));

echo ("<script> top.location.href = '". $ login_url. "' </ script>");

} Else {$ token = $ facebook-> getAccessToken ();

   try {
         $ post = $ facebook-> api ("/ me / feed", "POST", array (

             'message' => "Message Body",
             'name' => "Post Title"
             'caption' => "Caption Zone"
             'description' => 'Description',
             'link' => "www.miosito.it"
             'picture' => "www.miosito.it / mypicture.png"
         ));
   }
    catch (FacebookApiException $ e) {
       $ result = $ e-> getResult ();
      }
   }
?>

Alter them voices "'message', 'name', 'caption', 'description', 'link', 'picture'" with the content you want to publish on the bulletin board and you're done, you can publish on Facebook wall using PHP!

Pdf file with php


Today I will explain how to create PDF on the fly with php!

First download the library from here http://www.fpdf.org/ FPDF.

Copied to the root directory of your server.

Create a file CreatorePdf.php and stick the following code:

require('fpdf/fpdf.php');
<?
//create a new object pdf
 $pdf=new FPDF();

 / / set the file properties
 $pdf->SetAuthor('Author');
 $pdf->SetTitle("Questo è il titolo del Pdf");

/ / set font for the entire document
 $pdf->SetFont('Helvetica','B',20);
 $pdf->SetTextColor(50,60,100);

//create the page
 $pdf->AddPage('P');
 $pdf->SetDisplayMode(real,'default');


  / / Create a title with an edge
 $pdf->SetXY(50,20);
 $pdf->SetDrawColor(50,60,100);
 $pdf->Cell(100,10,'Testo centrato',1,0,'C',0);

 
 $pdf->SetXY (10,50);
 $pdf->SetFontSize(10);
  $pdf->MultiCell(200,10,"Scrivete qui il corpo della pagina");

/ / Export the file
 $pdf->Output("MioFile.pdf",'I');
  ?>



As you can see nothing difficult!

Good Job!

venerdì 17 maggio 2013

How to find out who deleted you from Facebook friends

              Have you ever wondered if any of your friends you have deleted from Facebook?


                            Now you can find out what your friends have deleted from Facebook!

How?

The answer is simple:

Join Infamous Friends at www.thethings.it/index.php?ln=en;

Simply enter the site and click on "Login with Facebook"!

Then, whenever you have doubts that you have deleted some of your friends,


you can just go back on the site and you'll know who did it!


I enclose some Screenshot site:









Come scoprire chi ti ha cancellato da Facebook!

Ti sei mai chiesto se qualcuno dei tuoi amici ti abbia cancellato da Facebook?

Da oggi puoi scoprire quali tuoi amici di hanno cancellato da Facebook!


Come?

La risposta è semplice:

Entra su Infamous Friends all'indirizzo www.thethings.it.

Vi basterà entrare sul sito e cliccare sul pulsante "Accedi con Facebook"!

Dopodichè, tutte le volte che avrete il dubbio che qualche vostro amico vi abbia cancellato,
vi basterà rientrare sul sito e saprete chi è stato!

 

Allego alcune Screnshot del sito: