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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:34:27+00:00 2026-06-08T16:34:27+00:00

I need to retrieve the html contents (source) of the pages, for example: www.google.com

  • 0

I need to retrieve the html contents (source) of the pages, for example: http://www.google.com page. Then i can use: file_get_contents or curl_init with PHP.

Exactly as someones question before here:
How do I get the HTML code of a web page in PHP?

But more then that for me, some of the pages are Access Required.
But i have granted access and know the password.

(Lets say it ask password with a form and the password is “abcd”.)

So how do i read that pages programmatically with PHP?

Updated (the answer, for me):
I found the solution with curl-setopt suggested by Bekzat Abdiraimov below. Then now i posted detail the codes here that i found somewhere and modified:

<?php
function curl_grab_page($url, $ref_url, $data, $login, $proxy, $proxystatus){
    if($login == 'true') {
        $fp = fopen("cookie.txt", "w");
        fclose($fp);
    }

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    if ($proxystatus == 'true') {
        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
        curl_setopt($ch, CURLOPT_PROXY, $proxy);
    }

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $ref_url);

    curl_setopt($ch, CURLOPT_HEADER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

    curl_exec($ch);

    curl_setopt($ch,CURLOPT_URL,$ref_url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);

    ob_start();
    $data = curl_exec($ch);
    ob_end_clean();

    curl_close($ch);
    return $data;
}

/*
 * $auth_processing_url .. is the posted 'action' url in login form like <form method=post action='http://www.abc.com/login.asp'> So it should be like: "http://www.abc.com/login.asp"
 * $url_to_go_after_login .. is the url you want to go (to be redireced) after login
 * $login_post_values .. are the form input names what Login Form is asking. E.g on form: <input name="username" /><input name="password" />. So it should be: "username=4lvin&password=mypasswd"
 */
echo curl_grab_page($auth_processing_url, $url_to_go_after_login, $login_post_values, "true",  "null", "false");
?>
  • 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-06-08T16:34:28+00:00Added an answer on June 8, 2026 at 4:34 pm

    Use curl
    curl_setopt ( resource $ch , int $option , mixed $value )

    option = CURLOPT_HTTPAUTH
    value = choose auth type (CURLAUTH_BASIC, ...)
    

    http://www.php.net/manual/en/function.curl-setopt.php

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

Sidebar

Related Questions

I need to retrieve a value from a website (can vary and I have
i need to retrieve the page title from an URL i already have using
I need to retrieve some some raw HTML from a certain part of an
I need to get the contents of a page (which is just an image)
I need download some html content (pages) made for iphone (or mobile devices) using
I'm currently using innerHTML to retrieve the contents of an HTML element and I've
Im trying to retrieve data from http://www.facebook.com/ajax/shares/view/?target_fbid=410558838979218&__a=1 I get mix of js and html
Currently I use the file_get_contents command to include the html of a file. Now
In the HTML below, I need to retrieve the p_id attribute based on the
Hi I'm new to Oracle 10g. I need retrieve the all the sublist from

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.