How To Use cURL (in PHP) For Authentication And SSL Communication Come usare cURL (in PHP) per l'autenticazione e SSL Comunicazione
Using cURL (in PHP) to access http s url is often not as simple as using the proper url. Utilizzando cURL (in PHP) per accedere a s url http spesso non è così semplice come con il corretto url. Using it for authentication is also not very clearly documented. Di utilizzare per l'autenticazione, inoltre, non è molto chiaramente documentate. This is a mini tutorial for both accessing https url’s as well as for http authentication. Si tratta di un mini tutorial sia per l'accesso a https URL e per l'autenticazione HTTP.
The following is a simple example which show the most common options you will ever need to use to access https url’s as well as for http authentication. Il seguente è un semplice esempio che mostra il più comune opzioni che si dovrà mai utilizzare per accedere a https URL e per l'autenticazione HTTP.
// The usual - init a curl session and set the url / / Il solito - init curl uno sessione e impostare l'url
$ch = curl_init(); $ ch = curl_init ();
curl_setopt($ch, CURLOPT_URL, $base_url); curl_setopt ($ ch, CURLOPT_URL, $ base_url);
// Set your login and password for authentication / / Imposta il tuo login e la password per l'autenticazione
curl_setopt($ch, CURLOPT_USERPWD, ‘login:pasword’); curl_setopt ($ ch, CURLOPT_USERPWD, 'login: password');
// You can use CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, / / È possibile utilizzare CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE,
// CURLAUTH_NTLM, CURLAUTH_ANY, and CURLAUTH_ANYSAFE / / CURLAUTH_NTLM, CURLAUTH_ANY, e CURLAUTH_ANYSAFE
// / /
// You can use the bitwise | (or) operator to combine more than one method. / / È possibile utilizzare il bit | (o) operatore di combinare più di un metodo.
// If you do this, CURL will poll the server to see what methods it supports and pick the best one. / / In questo caso, CURL sondaggio sarà il server per vedere quali metodi esso supporta e scegliere il migliore.
// / /
// CURLAUTH_ANY is an alias for CURLAUTH_BASIC | CURLAUTH_DIGEST | / / CURLAUTH_ANY è un alias per CURLAUTH_BASIC | CURLAUTH_DIGEST |
// CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM / / CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
// / /
// CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | / / CURLAUTH_ANYSAFE è un alias per CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE |
// CURLAUTH_NTLM / / CURLAUTH_NTLM
// / /
// Personally I prefer CURLAUTH_ANY as it covers all bases / / Personalmente preferisco CURLAUTH_ANY in quanto copre tutte le basi
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt ($ ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// This is occassionally required to stop CURL from verifying the peer’s certificate. / / Questo è talvolta necessario per fermare CURL dal verificare i peer certificato.
// CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if / / CURLOPT_SSL_VERIFYHOST può anche avere bisogno di TRUE o FALSE se
// CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a / / CURLOPT_SSL_VERIFYPEER è disabilitata (il default è 2 - controllare l'esistenza di un
// common name and also verify that it matches the hostname provided) / / Nome comune e verificare inoltre che corrisponda al nome host fornito)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false);
// Optional: Return the result instead of printing it / / Opzionale: Torna il risultato invece di stamparlo
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);
// The usual - get the data and close the session / / Il solito - ottenere i dati e chiudere la sessione
$data = curl_exec($ch); $ data = curl_exec ($ ch);
curl_close($ch); curl_close ($ ch);
Use the above as a template for your code to simplify your data access using cURL. Utilizzare il sopra come un modello per il tuo codice per semplificare il vostro accesso ai dati utilizzando l'arricciatura.
PS. The challenge with cURL documentation in PHP is that it is hard to find what you need from hundreds of available options and without enough examples of common use cases. La sfida con curl documentazione in PHP è che è difficile trovare di che cosa avete bisogno di centinaia di opzioni disponibili e senza abbastanza esempi di casi d'uso comune. What is needed is a series of How-To’s like the mini-tutorial above. Ciò che è necessario è una serie di How-To come il mini-tutorial di cui sopra.
Filed under Elencato sotto Computer Security Computer Security , Headline News Headline News , How To Come , PHP , Tech Note Nota tech , Web , Web Services Servizi Web | |
| |
RSS 2.0 RSS 2,0 | |
Trackback this Article | questo articolo |
Email this Article Invia questo articolo
You may also like to read Si può anche leggere come |





October 31st, 2006 at 10:06 pm 31 ottobre 2006 alle 10:06 pm
[...] Let’s take a PHP script that does a number of CURL calls as an example. [...] Prendiamo uno script PHP che fa un certo numero di CURL chiede come esempio. PHP gives you access to libcurl a really powerful tool for calling up other web pages, web services, RSS feeds, and whatever else you can dream up, right in your PHP code. PHP ti consente di accedere a libcurl davvero un potente strumento di esigere altre pagine web, servizi web, feed RSS, e quant'altro si può sognare, proprio nel vostro codice PHP. This article is not a general introduction to CURL, so I won’t go into detail, but basically the CURL functions allow your code to make requests and get responses from web sites just like a browser. Questo articolo non è una introduzione generale alla CURL, per cui non entrerò nei dettagli, ma sostanzialmente le funzioni CURL consentire il tuo codice di presentare richieste e ottenere risposte da siti Web come un browser. You can then parse the results use the data on your site. È quindi possibile analizzare i risultati utilizzare i dati sul tuo sito. [...]
November 2nd, 2006 at 4:48 am 2 novembre 2006 a 4:48 am
[...] [...] [...] [...]
November 28th, 2007 at 12:02 pm 28 novembre 2007 alle 12:02 pm
Thank you for this article and all of the information you’ve provided. La ringrazio per questo articolo e tutte le informazioni che ci hai fornito.
After I had my prototype remote log-in system working, I moved it to a secure server, and nothing worked anymore. Dopo ho avuto il mio prototipo di telecomando log-in sistema di lavoro, mi sono trasferita a un server sicuro, e nulla più lavorato.
Then I Googled for a couple of hours, until I found this page. Poi ho Googled per un paio di ore, fino a quando ho trovato questa pagina. Awesome! Impressionante! Everything is working again. Tutto è lavorare di nuovo.
Yes, you are absolutely right: It’sa jungle out there when you’re trying to find which CURL options are applicable and will actually work with any given situation. Sì, lei ha assolutamente ragione: Si tratta di una giungla là fuori quando stai cercando di trovare CURL opzioni che sono applicabili e in effetti lavorare con qualsiasi data situazione.
Hats off to you! Cappelli fuori a voi! You made my day! Lei ha fatto il mio giorno!
January 15th, 2008 at 2:46 pm 15 Gennaio, 2008 2:46 pm
Thanks for the info. Grazie per le informazioni.
One small thing: curl_exec() should have $ch as the parameter: Una piccola cosa: curl_exec () dovrebbero avere $ ch come il parametro:
$data = curl_exec($ch);$ data = curl_exec ($ ch);January 15th, 2008 at 10:50 pm 15 Gennaio, 2008 10:50 pm
Thanks. Grazie. Corrected. Rettificato.
March 29th, 2008 at 6:22 am 29 marzo 2008, 6:22 am
// CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | / / CURLAUTH_ANYSAFE è un alias per CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE |
// CURLAUTH_NTLM / / CURLAUTH_NTLM
// / /
problem pls check it… PLS problema controllare…
May 7th, 2008 at 9:00 am 7 maggio 2008, 9:00 am
hello, Ciao,
I tried ur code for a different website but it says there is syntax error(unexpected ‘:’ in that specific line in the line which we are supposed to edit our username and password to that site.. as i looking fro such similar login codes i would be thankful if u could help, Ho provato ur codice per un altro sito web, ma si dice c'è errore di sintassi (inattesi ':' in linea specifica che la linea in cui ci si suppone per modificare il nostro nome utente e la password per il sito .. Come ho guardando fro tali codici di accesso simili Le sarei grato se e potrebbe contribuire,
Thanks and regards, Grazie e saluti,
Rahul.. Rahul ..