Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:58:20+00:00 2026-05-29T09:58:20+00:00

I’m trying to login to a site via PHP cURL and I’m only getting

  • 0

I’m trying to login to a site via PHP cURL and I’m only getting “Bad Request” responses.

I played around with hosts file and set it to my server to check which Request Headers my browser sends and compare it to the request headers sent by cURL.

Everything is equal, except of:

Browser:

Content-Type: application/x-www-form-urlencoded
Content-Length: 51

PHP cURL:

Content-Length: 51, 359
Content-Type: application/x-www-form-urlencoded; boundary=----------------------------5a377b7e6ba7

I already set that values with this command, but it still sends the wrong headers:

curl_setopt($this->hCurl, CURLOPT_HTTPHEADER, array(
    'Expect:',
    'Content-Type: application/x-www-form-urlencoded',
    'Content-Length: 51' 
));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:58:21+00:00Added an answer on May 29, 2026 at 9:58 am

    You shouldn’t have to set the content-length yourself. If you use cURL to send an HTTP POST, it will calculate the content length for you.

    If you set the CURLOPT_POSTFIELDS value as an array, it will automatically submit the request as multipart/form-data and use a boundary. If you pass a string, it will use application/x-www-form-urlencoded so make sure you pass a urlencoded string to CURLOPT_POSTFIELDS and not an array since you want form-urlencoded.

    You need to be doing this:

    $data = 'name=' . urlencode($value) . '&name2=' . urlencode($value2);
    curl_setopt($this->hCurl, CURLOPT_POSTFIELDS, $data);
    
    // NOT
    
    $dataArray = array('name' => 'value', 'name2' => 'value2');
    curl_setopt($this->hCurl, CURLOPT_POSTFIELDS, $dataArray);
    

    In either case, you do not need to set the content length, but you have to use the first method to get application/x-www-form-urlencoded encoding on the form.

    If that doesn’t help, post all the code relevant to setting up the curl request, (all the options, and data you are passing to it) and that should help solve the problem.

    EDIT:

    Added is an example I came up with that works (I get failed login).

    <?php
    
    $URL_HOME  = 'http://ilocalis.com/';
    $LOGIN_URL = 'https://ilocalis.com/login.php';
    
    $ch = curl_init($URL_HOME);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    
    $home = curl_exec($ch);
    
    //echo $home;
    
    $post = array('username' => 'drew', 'password' => 'testing 123');
    $query = http_build_query($post);
    
    curl_setopt($ch, CURLOPT_URL, $LOGIN_URL);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
    
    $login = curl_exec($ch);
    
    echo $login;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.