Wednesday, September 3, 2014

Using cURL on a server

Using cURL on a server - The cURL library allows PHP developers to connect to external Web sites. You use the cURL library to read the contents of another web site, send data to an external web site or use the API of the external website. The cURL library handles all the necessary commands to connect to the external web site, so all you have to do is specify the website with cURL initialization function.

Instructions

1. Right click on the PHP file you want to use to connect to external website. Click on "Open with" and select your favorite PHP editor.

2. Open the website you want to extract data. The following command connects to the external website using cURL: $ url = curl_init ("http://misitio.com/"); Replace "misitio.com" with the URL to which you want to connect.

3. Opens a file to copy the results. If you want to copy the results to a local file, add the following code to the PHP function: $ copy = fopen ("contenido_descargado.txt", "w"); Replaces the TXT file with the file name you want to use. Using this function, the entire text of "misitio.com" and the HTML file will be downloaded "contenido_descargado.txt" on your server.

4. Close the file and the connection to the external server. You must close the connection to the file server and the connection to free memory on the server. Add the following code at the end of the PHP function: curl_close ($ ur); fclose ($ copy);