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

  • Home
  • SEARCH
  • 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 1021419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:18:30+00:00 2026-05-16T11:18:30+00:00

UPDATE: Turns out my code works. Browser was caching previous failed response. Thanks for

  • 0

UPDATE: Turns out my code works. Browser was caching previous failed response. Thanks for the pointers.

I’m building a prototype and one thing I’d like to do is perform a service if the user is a valid member of NYTimes.com by providing their credentials.

Using curl, I’m trying to perform a login to the site, and then check for success or failure.

My code, below, doesn’t return errors but drops me back at the login page:

<?php
class Login {

    function Verify() {
        print $this->getContent();
    }

    function getContent() {

        $url    = 'http://www.nytimes.com/auth/login';

        // URI can be any NYT web page to be redirected to upon successful login
        // SAVEOPTION and Submit2 are Optional but in original web form so included here

        $fields = array(
            'is_continue'=> 'true',
            'USERID'     => urlencode('ENTER_YOUR_USERNAME'),
            'PASSWORD'   => urlencode('ENTER_A_PASSWORD'),
            'URI'        => urlencode('http://www.nytimes.com/robots.txt'), 
            'OQ'         => '',
            'OP'         => '',
            'SAVEOPTION' => 'YES',
            'Submit2'    => 'Log In'
        );

        $fields_string = '';

        if(!$curld = curl_init($url)) {
            echo "Could not connect to the specified resource";
               exit;
        }
        $ch        = curl_init();
        $useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
        rtrim($fields_string,'&');

        curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_COOKIEJAR, "curl_login_cookie.txt");

        curl_setopt($ch ,CURLOPT_POST, count($fields));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

        ob_start();
        curl_exec ($ch);

        curl_close ($ch);
        $result = ob_get_contents();
        ob_end_clean();

        return $result;
    }
}

$login  = new Login;
$result = $login->Verify();
?>

Any pointers, or suggestions welcome.

  • 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-16T11:18:31+00:00Added an answer on May 16, 2026 at 11:18 am

    You need to check that the result of curl_exec is not false (which it’ll be if the execution failed).

    If it’s succeeding, try checking the results of curl_errno and curl_getinfo to see information about the operation.

    Also, it might be better to set the CURLOPT_RETURNTRANSFER option on your curl object instead of using output buffering to capture the result.

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

Sidebar

Related Questions

No related questions found

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.