Solved

PHP CURL Cookie

Posted on 2011-03-19
4
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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 110

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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

734 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