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 3619814
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:55:34+00:00 2026-05-18T22:55:34+00:00

I want to loginto a site using curl and then get resulting page. for

  • 0

I want to loginto a site using curl and then get resulting page. for example i want to run a script and see my yahoo mail page. i wrote something like this.

//set POST variables
$url = 'http://localhost/test/login';
$fields = array(
                        'username'=>'abc',
                        'password'=>'def'
                );
$fields_string='';
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
echo $result;

login.php

echo $_POST['username'];
echo $_POST['password'];

header('Location: http://www.xyz.com/');

script posts data to login.php but contents of xyz.com are not shown.

  • 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-18T22:55:35+00:00Added an answer on May 18, 2026 at 10:55 pm

    By logging into a Website you normaly generate a Session ID which is stored in a Session. By logging in with CURL you didn’t save this cookie in your Client Browser, you maybe logged in with your server, but there is no way to be logged in with your client.

    And of course change this line:

    echo $_POST['username'];
    echo $_POST['password'];
    
    header('Location: http://www.xyz.com/');
    

    to the following:

    header('Location: http://www.xyz.com/');
    echo $_POST['username'];
    echo $_POST['password'];
    

    or use ob_start(); on the beginning of your script.

    …which doesn’t make sence because you’ll never see that content 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Want to run javascript function from parent window in child window Example I have
I want to login to a site using WebRequest and later show site (logged)
I am trying to get WWW::Mechanize to login to Yahoo using https; however, it
I want to login to a site using HttpClient and after logging in I
When I try to login to this site using my yahoo openid, it takes
want to know why String behaves like value type while using ==. String s1
Want the function to sort the table by HP but if duplicate HPs then
I want to login to a site like stackoverflow or codeproject from a server.
I have implanted a login code to a site , after that I want
The home page of this site will have basically a 3 column layout. I

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.