Luckmoshy
By Luckmoshy · Published:
Last updated: · No comments
  • ARTICLE: PHP LESSON

  • What is the curl request in PHP?

    The PHP cURL stands for ‘Client for URLs’, curl is a PHP inbuilt library that is the most powerful extension. It allows the user to create the HTTP requests in PHP. Think about API (API works like a mediator between two servers), so we need a library while creating an API for communicating between two servers through URL.

    wht is curl request php?

    The PHP cURL library is used to communicate one server to other servers with the help of protocols.

    In simple words cURL allows us to send and receive the data through the URL syntax. cURL makes it easy to communicate between different websites and domains.

    Usage and cURL Functions
    S. No Function Name Description
    1. curl_init() Function will start a new session and return a cURL handle
    2. curl_setopt() This function defines a various option for the cURL session.
    3. curl_setopt($ch, option, value) This function is used to set an option for a cURl session and the value for a cURL session by the "ch" parameter.
    3. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) This function return page contents. If set false or 0 then no output will be returned.
    3. curl_setopt($ch, CURLOPT_URL, $url) This function pass URL as a parameter. $url is our target server web address. in simple words this is the URL that we want to get from the internet
    4. curl_exec() This function executes the cURL session, and it should be start after initializing a curl and all the options are set for the session, It's actual use to execute the predefined cURL session (defined by ch)
    5. curl_close() This function is used to close curl resource and free up system resources.
    <?php
    $url = "https://yekrinaweb.com/about-me";
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $url);
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    
    echo $result;
    ?>

    Comments



    UFllRXRaZDJpLytvYUpFSzZoL1c3NWRTbkltV2VJeEgwMUo1Y3ZvNEU0bz01