Jump to content

Need help with cURL


Pain

Recommended Posts

Hi. I am fairly new with cURL.

 

I have a URL like example.com/index.php?something=value&somethingtwo=valuetwo

 

How can I get those values and print them out?

 

I've got this code, but have no idea what to do next, please help guys!

 

 

<?php
 
 
function get($url, $params=array()) 
{ 
 
    $url = $url.'?'.http_build_query($params, '', '&');
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $url);
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        
    $response = curl_exec($ch);
    
    curl_close($ch);
    
    return $response;
}
 
// Sample call
 
echo get('https://www.example.com/index.php', array('something'=>'value', 'somethingtwo'=>'valuetwo'));
 
 
?>
Link to comment
Share on other sites

First of all: Guys, please, please stop copying and pasting crap code you found somewhere on the Internet.

 

I understand that you're new to cURL. But the answer to this problem is to learn, not adopt the first piece of code you've stumbled upon. After 4 years, you should know that most code is plain crap and pretty much the last thing you want on your server.

 

This line silently breaks the security of all HTTPS connections by turning off certificate verification:

 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

 

That's obviously a very, very bad idea, because the whole reason for using HTTPS is security. Even worse, this “feature” isn't documented anywhere in the code you've posted. It just sits there waiting to take effect when you least expect it.

 

Actually, the only reason why this option is used at all is because people don't know how to set up HTTPS, run into an error and decide to “solve” this problem by effectively deactivating HTTPS. How intelligent.

 

So don't use the code. Take some time to learn cURL and then write your own code.

 

 

 

How can I get those values and print them out?

 

Get which values?

Edited by Jacques1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.