Jump to content

cURL Post help


ilikemath2002

Recommended Posts

I use my site as a way to remotely login to another site. Recently the site change from GET to POST, and now I have to use cURL to do it.

 

Info about the site:

- It uses post

- It uses SSL

 

My script isn't working!

<?php 
ini_set('display_errors', 1);
error_reporting(E_ALL);
$user    = $_POST['username'];
$pass   = $_POST['password'];
$ch = curl_init();
   curl_setopt($ch, CURLOPT_URL,"WEBSITEURLGOESHERE?");
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS,"username=" . $user . "&password=" . $pass .);

   $pagedata = curl_exec($ch);
   curl_close($ch);

I've verified that the form names are correct, but should there be a ? on the end of my website URL since it's POST not GET. If not, what do I need to change to make it POST instead of GET?

 

At the moment the script returns Invalid Username/Pass, but I know that information is correct.

 

EDIT: Getting this error:

curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /home/site/public_html/dir

This isn't related to the problem but how do I fix that?

Link to comment
https://forums.phpfreaks.com/topic/142329-curl-post-help/
Share on other sites

I check your script and your syntax usage of the function curl_setopt() seems to be incorrect. Try the following and if it works, you can try uncommenting the commented line in the following:

<?php 
ini_set('display_errors', 1);
error_reporting(E_ALL);
$user    = $_POST['username'];
$pass   = $_POST['password'];
$ch = curl_init();
   curl_setopt($ch, CURLOPT_URL,"WEBSITEURLGOESHERE?");
   //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_POSTFIELDS,"username=" . $user . "&password=" . $pass .);

   $pagedata = curl_exec($ch);
   curl_close($ch);

Hope that helps.

Link to comment
https://forums.phpfreaks.com/topic/142329-curl-post-help/#findComment-745782
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.