Login to Website using cURL & PHP

thahelper · 88K views · 2015 · 6:58

Open on YouTube

Web developmentPython, Ruby & scripting languagestutorial

Why Stack Overflow recommends it

Stack Overflow users cite it as the source of the PHP cURL login-and-cookie-file pattern they build on when they want a script to sign in to a site automatically.

Recommended by 0 people across 0 different months, 2016 to 2016.

What it is

A short 2015 screencast by the channel thahelper showing how to log in to a website from PHP using the cURL extension. It walks through a script that stores cookies, posts form data and fetches pages as a logged-in visitor, with the code shared on Pastebin.

What people said

Cites user3877230 · 2016-01 · Stack Overflow · on “Log into website and get specifc site in CURL?”

Lets say i make a HTTP-Request with CURL like this(thanks for this source to thahelper [this video] by the way): REQUEST.PHP <?PHP function curlRequest($url,$data) { $fp = fopen("cookie.txt", "w"); fclose($fp); $login = curl_init(); curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt"); curl_setopt($login, CURLOPT_TIMEOUT, 40000); curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($login, CURLOPT_URL, $url); curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($login, CURLOPT_POST, TRUE); curl_setopt($login, CURLOPT_POSTFIELDS, $data); ob_start(); return

Cites cronos · 2016-02 · Stack Overflow · on “How to log in to a website automatically?”

I have been trying to work on this project for a long time. I need to find a way to log in automatically to this website so people see the calendar information without using the credentials every time. So far, the best approach is a code in php using "curl" from this YouTube video [this video] ; the problem is that the login system doesn't use a "Post" or "Get", it uses some kind of "xml" with weird information. This is the login link [LINK] Credentials: Url -> [LINK] User -> test Password -> 1234 Any information will be appreciated! code: <?php //Upload a blank cookie.txt to the same directory as this file with a CHMOD/Permission to 777 function login($url,$data){ $fp = fopen("cookie.txt", "w");

Cites cmcgeecc · 2016-07 · Stack Overflow · on “Why can Chrome execute javascript on other pages but I can't?”

I'm going to assume that you are looking to grab data from these pages that aren't yours and store it somewhere. I have done this before with curl using php. If you are looking to display these sites for users to interact in a different way, but starting from a page that is yours, you may be able to render these pages by grabbing the source html using curl and rendering it as a sort of proxy. I've used this tutorial for something similar [this video] . Hopefully this gives you a start. I think you should be a little more detailed in your question though to get more help.