Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Le client HTTP PHP5

988 views

Published on

Présentation de l'utilisation du client HTTP de PHP 5

Published in: Engineering
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes.........ACCESS WEBSITE Over for All Ebooks ..... (Unlimited) ......................................................................................................................... Download FULL PDF EBOOK here { https://urlzs.com/UABbn } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • If you want to download or read this book, Copy link or url below in the New tab ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Le client HTTP PHP5

  1. 1. Jean-Marie Renouard LightPath 2014©
  2. 2. Le logo PHP est du domaine public http://commons.wikimedia.org/wiki/File:PHP-logo.svg Ce document est licencié sous licence ◦Attribution-NonCommercial-ShareAlike ◦CC BY-NC-SA Plus de détails: http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ LightPath 2014© - http://www.jmrenouard.fr 2
  3. 3. Base de l’accès HTTP Récupération d’un page WEB Récupération dans un fichier Poster des données de formulaire Nettoyage des données Positionner des entêtes HTTP Passer l’authentification Sécurisation HTTPS Accès multiples LightPath 2014© - http://www.jmrenouard.fr 3
  4. 4. LightPath 2014© - http://www.jmrenouard.fr 4
  5. 5. Curl_init: initialise une session HTTP Curl_setopt: initialise les options ◦Entête HTTP ◦Authentification ◦User-agent ◦… Curl_exec: exécution d’un requête HTTP Curl_close: fermeture de la session HTTP LightPath 2014© - http://www.jmrenouard.fr 5
  6. 6. LightPath 2014© - http://www.jmrenouard.fr 6
  7. 7. <?php // Création d'une nouvelle ressource cURL $ch = curl_init(); // Configuration de l'URL et d'autres options curl_setopt($ch, CURLOPT_URL, "http://www.php.net/"); curl_setopt($ch, CURLOPT_HEADER, 0); // Récupération de l'URL et affichage sur le naviguateur curl_exec($ch); // Fermeture de la session cURL curl_close($ch); ?> LightPath 2014© - http://www.jmrenouard.fr 7
  8. 8. LightPath 2014© - http://www.jmrenouard.fr 8
  9. 9. Sortie par défaut, la sortie standard. Possibilité de stocker dans un fichier $ch = curl_init("http://www.example.com/"); $fp = fopen("page.html", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); LightPath 2014© - http://www.jmrenouard.fr 9
  10. 10. LightPath 2014© - http://www.jmrenouard.fr 10
  11. 11. GET: par défaut GET; curl_setopt($ch, CURLOPT_HTTPGET, true); POST: curl_setopt($ch, CURLOPT_POST, true); PUT :POST: curl_setopt($ch, CURLOPT_PUT, true); TRACE / HEAD: pas disponible LightPath 2014© - http://www.jmrenouard.fr 11
  12. 12. … <input type="text" name="firstName" value="Name"> <input type="text" name=« lastName" value="Name"> … LightPath 2014© - http://www.jmrenouard.fr 12
  13. 13. Urlencode: fonction d’encodage pour URL. $post_data['firstName'] = ‘Jean-Marie'; $post_data[‘lastName'] = ‘Renouard‘; foreach ( $post_data as $key => $value) { $post_items[] = urlencode($key) . '=' . urlencode($value); } $post_string = implode ('&', $post_items); LightPath 2014© - http://www.jmrenouard.fr 13
  14. 14. curl_setopt( $curl_connection, CURLOPT_POSTFIELDS, $post_string); LightPath 2014© - http://www.jmrenouard.fr 14
  15. 15. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.php.net/"); curl_setopt($ch, CURLOPT_POST, true); $post_data['firstName'] = ‘Jean-Marie'; $post_data[‘lastName'] = ‘Renouard‘; foreach ( $post_data as $key => $value) { $post_items[] = urlencode($key) . '=' . urlencode($value); } $post_string = implode ('&', $post_items); curl_setopt($ch,CURLOPT_POSTFIELDS, $post_string); curl_exec($ch); curl_close($ch); LightPath 2014© - http://www.jmrenouard.fr 15
  16. 16. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.php.net/"); curl_setopt($ch, CURLOPT_POST, true); $post_data['firstName'] = ‘Jean-Marie'; $post_data[‘lastName'] = ‘Renouard‘; curl_setopt($ch,CURLOPT_POSTFIELDS, $post_data); curl_exec($ch); curl_close($ch); LightPath 2014© - http://www.jmrenouard.fr 16
  17. 17. LightPath 2014© - http://www.jmrenouard.fr 17
  18. 18. Urlencode: encodage des données POST Les données postées par CURL doivent être url encodées afin de conserver le format des données. LightPath 2014© - http://www.jmrenouard.fr 18
  19. 19. htmlentities: encodage des caractères en entités HTML html_entity_decode: décodage des entités HTML. Idéal, lors de la réception de page Web. LightPath 2014© - http://www.jmrenouard.fr 19
  20. 20. Strip_tags: retrait des tags HTML. Idéal pour la conservation au format TXT LightPath 2014© - http://www.jmrenouard.fr 20
  21. 21. <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.php.net/"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANFER, true); $page=curl_exec($ch); $page=strip_tags($page); $page= html_entity_decode($page); curl_close($ch); file_put_contents(« result.txt », $page); ?> LightPath 2014© - http://www.jmrenouard.fr 21
  22. 22. LightPath 2014© - http://www.jmrenouard.fr 22
  23. 23. Indication du navigateur utilisé. ◦curl_setopt($ch, CURLOPT_USERAGENT, « Mozilla/5.0 »); Indication de la page d’origine de l’appel ◦curl_setopt($ch, CURLOPT_REFERER, « http://www.google.com/ »); LightPath 2014© - http://www.jmrenouard.fr 23
  24. 24. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); Jusqu’à un certain point, je veux bien suivre: curl_setopt($ch, CURLOPT_MAXRES, 10); LightPath 2014© - http://www.jmrenouard.fr 24
  25. 25. Il est possible d’ajouter ses entêtes HTTP $headers= array ( "Content-Type: text/xml; charset=utf-8", "Expect: 100-continue" ) ; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); LightPath 2014© - http://www.jmrenouard.fr 25
  26. 26. LightPath 2014© - http://www.jmrenouard.fr 26
  27. 27. 2 appels pour initialiser l’authentification type BASIC Format des données d’authentification : ◦[login] : [password] Appels à réaliser: ◦curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ; ◦curl_setopt($curl, CURLOPT_USERPWD, "username:password"); LightPath 2014© - http://www.jmrenouard.fr 27
  28. 28. Curl supporte plusieurs type d’authentification. ◦curl_setopt($curl, CURLOPT_HTTPAUTH, XXXX ) ; Types d’authentification possibles: ◦CURLAUTH_BASIC ◦CURLAUTH_DIGEST ◦ CURLAUTH_GSSNEGOTIATE ◦ CURLAUTH_NTLM ◦ CURLAUTH_ANY: idéal pour passer une authentification ◦CURLAUTH_ANYSAFE. LightPath 2014© - http://www.jmrenouard.fr 28
  29. 29. LightPath 2014© - http://www.jmrenouard.fr 29
  30. 30. Activation du HTTPS sans vérification. ◦curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); LightPath 2014© - http://www.jmrenouard.fr 30
  31. 31. Récupérer le certificat X509 de l’autorité de certification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, SECURECA.crt"); LightPath 2014© - http://www.jmrenouard.fr 31
  32. 32. LightPath 2014© - http://www.jmrenouard.fr 32
  33. 33. Indication du proxy HTTP et de l’URL options = array( CURLOPT_HTTPPROXYTUNNEL=> 1, CURLOPT_PROXYTYPE => 'URLPROXY_HTTP', CURLOPT_PROXY => 'url_proxy:port' ); curl_setopt_array($ch, $options); LightPath 2014© - http://www.jmrenouard.fr 33
  34. 34. $options = array( CURLOPT_PROXYTYPE => 'URLPROXY_HTTP', curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); CURLOPT_PROXY => 'url_proxy:port', CURLOPT_PROXYAUTH =>'URLAUTH_ANY', CURLOPT_PROXYUSERPWD => $userpwd ); curl_setopt_array($ch, $options); LightPath 2014© - http://www.jmrenouard.fr 34
  35. 35. LightPath: ◦Société de conseil et d’ingénierie ◦Formations, Conseil, Audit et mise en oeuvre ◦jmrenouard@lightpath.fr Jean-Marie RENOUARD ◦jmrenouard@gmail.com ◦Twitter: @jmrenouard ◦http://www.jmrenouard.fr LightPath 2014© - http://www.jmrenouard.fr 35

×