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