Solved

PHP CURL Cookie

Posted on 2011-03-19
4
404 Views
Last Modified: 2013-12-25
Hi

I want to login to somesite in server side, then forward it's cookie to user's browser, I tried using COOKIEJAR and COOKIEFILE options, but it doesn't work. What can I do it?

Thanks
0
Comment
Question by:CSecurity
  • 2
4 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35171784
Can you show how you tried it?
It's not really clear if you have troubles with the CURL cookie options (fetching and writing on your server),
or that you have troubles putting the cookie from your server to the client and assuming that they can login on 'somesite' (write cookie from your server with a different domain), which is not possible.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35173573
Please post the exact URL you want to retrieve cookies from, along with any code you have tried already.  I can show you demonstration scripts that use the CURL cookie jar, but it would be more practical to have a site to test with.  Thanks.
0
 
LVL 17

Accepted Solution

by:
selvol earned 250 total points
ID: 35174690
Check your Cookie path use \\ instead of \

Here's an example I use change the site to your site and the cookie path to your path.


Selvol


<?php
 $ch = curl_init();
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
      curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_COOKIEFILE, "C:\\Sol\\www\\phpr0xi_v0.6_2010\\exe2\\cookies.txt");
    curl_setopt($ch, CURLOPT_COOKIEJAR, "C:\\Sol\\www\\phpr0xi_v0.6_2010\\exe2\\cookies.txt");
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, 'http://SITE/search_post.html?Victim=smith&action=7CrmeBcr5tY%3D');
 $result1 = curl_exec($ch);
  if(preg_match('/<tr class="searchresultheading" bgcolor="#7A8EAD">(.*)<!-- Footer Nav -->/s', $result1, $avon))
  {
$avon =  str_replace("affirmation", "https://SITE/affirmation",  $avon[1]);
      echo $avon;
      }
      else
      {
    echo "No Results Found"; }
 flush();
 curl_close($ch); ?>

Open in new window

0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 35175179
use \\ instead of \

I think you can also use the predefined and OS-aware PHP constant, DIRECTORY_SEPARATOR
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now