CURL can not access Cookies or Session?

I was brought on a project to finish working on a CMS… The page system uses this

if(isset($_GET['page']))
  {
    $page = page($_GET['page']);

    $location = "./styles/{$get['path']}/pages/{$page}.php";
      if(file_exists($location) && $page != "index")
      {
        if($page == "donate" || "wpnmake" || "wpnconfirm" || "wpnbuy")
        {

          $location = 'domain.com'.$location;
          $ch = curl_init();
          curl_setopt($ch,CURLOPT_URL,$location);
          curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
          curl_setopt($ch,CURLOPT_HEADER, false);
          //step3
          $result=curl_exec($ch);
          //step4
          curl_close($ch);
          return $result;
        }
        else
        {
          $file = logged(file_get_contents($location));
        }
        return $file;

      }
      else
      {
        $location = "./styles/{$get['path']}/pages/not_found.php";
          $file = bbcode(logged(file_get_contents($location)));
            return $file;
      }

whenever i try and call the cookie $_COOKIE[‘login’] which is 100% set, I can access it when i use a file in the root directory. However when I go to a page like domain.com/?page=custompage
I have no access to sessions or cookies, is there anyway to get around that?

Long story short. User logs in gets assigned a cookie, I want to be able to pull that cookie from domain.com/?page=custompage, however it always tells me it is a invalid index.

$_COOKIE is what you get from the browser within PHP. CURL is another browser. You have to tell it to store arbritary cookies.

How do you go about doing that? I have done some research and can not get a grasp on it.

You check to see if there is an argument named “page” on the URL. If so, you process some Curl info.
In the first step, you acquire the page argument and put it into a variable.
Next you load a value of a styles from a variable named $get. $get[‘path’]
is that correct or was that also being passed? Normally you should not use keywords as variable names.
It gets extremely hard to follow.

To create a cookie using Curl, you do it something like this:

    //  Create And Save Cookies
    $tempfilename = dirname(__FILE__).'/cookie.txt';
    curl_setopt($session, CURLOPT_COOKIEJAR, $tempfilename);
    curl_setopt($session, CURLOPT_COOKIEFILE, $tempfilename);

You would add that before you exec the Curl…

To retrieve a cookie, you add this type of line before the exec…

curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);

That would place the cookies into a variable named $cookie_jar which you would then have to parse.

Hope that helps.

PS: To read or search for this in Google, use " php curl cookies " Note php first, then curl, …

Sponsor our Newsletter | Privacy Policy | Terms of Service