Solved

PHP CURL Cookie

Posted on 2011-03-19
4
407 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 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

22 Experts available now in Live!

Get 1:1 Help Now