Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP CURL Cookie

Posted on 2011-03-19
4
Medium Priority
?
445 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 111

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 1000 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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 is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

618 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