DaniWeb
Log In Sign Up
  • Read
  • Contribute
  • Meet
  1. Home
  2. Programming Forum
  3. Web Development Forum
  4. Code Snippet Repository
  5. Reusable Code Snippet

Curl login authentication cookie issues

12 Years Ago beanonymous 0 Tallied Votes 163 Views Share

OK here is a piece of code I've been working on that actually logs you in and returns what ever Curl sees except i have no idea how to make Curl function correctly with websites that require cookie authentication correctly, can anyone help? =/

php
<?php

//create array of data to be posted
  $post_data['username_here'] = "username";
  $post_data['password_here'] = "password";
  
  //traverse array and prepare data for posting (key1=value1)
  foreach ( $post_data as $key => $value) {
   $post_items[] = $key . '=' . $value;
  }
 
  //create the final string to be posted using implode()
  $post_string = implode ('&', $post_items);
  $post_string = "dest=%2".$post_string ."&submit=next";
  //i.e. ?dest=%2F&username=username_here&password=password_here&submit=next
  

  //create cURL connection  
  $curl_connection = curl_init("https://my.netspace.net.au/logincheck");
  
  //set options
  curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); //set time untill cURL times out
  curl_setopt($curl_connection, CURLOPT_USERAGENT, 
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"); // set HTTP User Agent
  curl_setopt($curl_connection, CURLOPT_HEADER,1);
  curl_setopt($curl_connection, CURLOPT_POST, 1);
  curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);//set data to be posted
  curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); // follow redirection if any...
  curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); //determin if to continue processing code if SSL certificate is verifyed or not...
  
  //cookie code ive found that dont seem to work...
  /*curl_setopt($curl_connection, CURLOPT_COOKIEFILE, "cookies.txt");
  curl_setopt($ch, CURLOPT_COOKIE, "cookies.txt");
  curl_setopt($curl_connection, CURLOPT_COOKIEJAR, "cookies.txt");
  curl_setopt($curl_connection, CURLOPT_COOKIESESSION, true); //return cookies that cURL collects*/
     
  //perform our request (execute request)
  $result = curl_exec($curl_connection);
  curl_close();
  echo $result;
?>
About the Author
Member Avatar
beanonymous 0 Newbie Poster
Be the first to reply
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.

Sign Up — It's Free!
Related Topics
  • Member Avatar login at youtube using cURL and php ? 3
  • Member Avatar Creating a PHP Bot 2
  • Member Avatar Urgent: Asp.net help 4
  • Member Avatar Cookie problem with mysql 4
  • Member Avatar PHP login authentication for multiple users 4
  • Member Avatar Last issue was resolved... but hey, I've got another 1
  • Member Avatar Login Script Integration with PHP/MySql Wordcount/Story Script. 4
  • Member Avatar login page validation in php 1
  • Member Avatar Help with a search form/page 3
  • Member Avatar login and register with php and mysql 4
  • Member Avatar PHP and cookies (and milk!) - probably a simple error 9
  • Member Avatar Reload/Redirect to a form without losing data 2
  • Member Avatar User authentication problem 1
  • Member Avatar MOVED - Curl & PHP 3
  • Member Avatar Calling images from MySQL using PHP 12
  • Member Avatar cURL doesn't return the page? 5
  • Member Avatar PHP Validation code 1
  • Member Avatar Printing the contents of a div, keeping styling 6
  • Member Avatar login.php 3
  • Member Avatar PHP code not working. Need help 8
Not what you need?

Reach out to all the awesome people in our web development community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions.

Start New Topic
Topics Feed
Reply to this Topic
This topic is old! No one has contributed to this discussion in over 12 years. Are you sure you have something valuable to add to revive the existing conversation? Consider starting a new topic instead. Otherwise, please be thoughtful, detailed and courteous, and adhere to our posting rules.
  • Edit
  • Preview

Share Post

Insert Code Block

  • Forum Categories
  • Hardware/Software
  • Programming
  • Digital Media
  • Community Center
  • Latest Content
  • Newest Topics
  • Latest Topics
  • Latest Posts
  • Top Tags
  • Topics Feed
  • Social
  • Meet People
  • Forums
  • Top Members
  • Community Functions
  • DaniWeb Premium
  • Newsletter Archive
  • Markdown Syntax
  • Community Rules
  • Developer APIs
  • Connect API
  • Forum API Docs
  • Tools
  • SEO Backlink Checker
  • Legal
  • Terms of Service
  • Privacy Policy
  • FAQ
  • About Us
  • Advertise
  • Contact Us
© 2023 DaniWeb® LLC