Solved

PHP CURL Cookie

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

689 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