The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 22, 2019, 06:08:09 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: curl and cookie problem  (Read 5738 times)
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« on: November 03, 2008, 04:05:28 PM »

Curl only sends one cookie. I have no clue how to solve this.
I would be grateful for your help.


Let me know if I shall post the real website address.

Code:
PostCurl("gbname=Natt&gbaddress=mail%40web.com&gbcomment=This+is+a+comment", "www.website.com/guestbook.html")


I receive this cookie file:
Code:
# Netscape HTTP Cookie File
# http://curlm.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

www.website.com FALSE / FALSE 0 gb76d0a24dd0c828b 48805199
www.website.com FALSE / FALSE 0 PHPSESSID hcu2sagveicu5pmje9i6a43qa7

The first cookie data row is not send.

Code:
function InitSettings(&$cookie, &$proxy, &$proxyport, &$agent)
{
    /********************Settings******************************/
    //$cookie = "cookie.txt";
    $cookie = "C:\wamp\www\cookie.txt";
    $proxy = "http://127.0.0.1";
    $proxyport = 8888;

    //$agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; sv-SE; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16';
    $agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; sv-SE; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3';

    /**********************************************************/
}


function PostCurl($PostData, $PostUrl)
{

    InitSettings($cookie, $proxy, $proxyport, $agent);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
    curl_setopt($ch, CURLOPT_URL, $PostUrl);
    //curl_setopt($ch, CURLOPT_HEADER, true);
    if (!empty($proxy))
    {
        curl_setopt($ch, CURLOPT_PROXY, $proxy);
        curl_setopt($ch, CURLOPT_PROXYPORT, $proxyport);
    }
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40);
    curl_setopt($ch, CURLOPT_TIMEOUT, 80);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_VERBOSE, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
    curl_setopt($ch, CURLOPT_SSLVERSION, 2);
    $data = curl_exec($ch);
    curl_close($ch);

    if (empty($data))
    {
        echo "<br>no data returned. Am I connected?";
    }
    return $data;
}
function GetCurl($url)
{

    InitSettings($cookie, $proxy, $proxyport, $agent);
    $ch = curl_init();


    curl_setopt($ch, CURLOPT_URL, $url);

    if (!empty($proxy))
    {
        curl_setopt($ch, CURLOPT_PROXY, $proxy);
        curl_setopt($ch, CURLOPT_PROXYPORT, $proxyport);
    }
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40);
    curl_setopt($ch, CURLOPT_TIMEOUT, 80);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_VERBOSE, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
    curl_setopt($ch, CURLOPT_SSLVERSION, 2);
    $data = curl_exec($ch);
    curl_close($ch);
    if (empty($data))
    {
        echo "<br>no data returned. Am I connected?";
    }

    return $data;
}



« Last Edit: November 03, 2008, 04:10:23 PM by nattsurfaren » Logged
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #1 on: November 04, 2008, 02:08:22 PM »

I'm trying to solve this with custom cookie handling.
I can retreive from header with the header option.
Here is the code that scrape the cookie info from header:

Code:
 
preg_match_all('/Set-Cookie: (.*)/mi', $data, $results);
  $cookiearr=array();
  foreach($results[1] as $key => $item)
  {
  if(!(strpos($item,";")===false))
  {
  preg_match("/(.*);/i",$item,$match);
  $cookiearr[]=$match[1];
  }
  else
  {
  $cookiearr[]=$item;
  }
  }
  dump($cookiearr);
    $cookies = implode(';', $cookiearr);
dump ($cookies);

I have tried to make an regexp that handle cases when there are no ";" involved but I ended up in this more ugly solution.
I would appreciate some help from a regexp guru to do this.

Sincerely Natt
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #2 on: November 04, 2008, 06:27:46 PM »

before I even take a stab at the regex, i need clarification.

Show me a couple strings which you want matched
and a few that you want to fail.
I understand the basic issue is you DONT want to capture if there is a ; in the string(s) right?
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #3 on: November 05, 2008, 10:41:26 AM »

before I even take a stab at the regex, i need clarification.

Show me a couple strings which you want matched
and a few that you want to fail.
I understand the basic issue is you DONT want to capture if there is a ; in the string(s) right?

Thaks nutballs,
I have found only two important variations to extract for next cookie send.
Example1:
Set-Cookie: name1=value; expires=Thu, 01 Jan 1970 00:00:05 GMT
Example2;
Set-Cookie: name1=value

Second without ';'

Wrong cookie row could be like:
name1=value; expires
name1=value expires=Thu, 01 Jan 1970 00:00:05 GMT

If more data than only one name and value pair always add an ;
Characters can be mixed lowercase uppercase and not predictable.

I think the important thing is to scrape info before ;
and scrape whole row if no ; exist.
I think Overdoing validity check like checking that '=' and ',' is correct, will only come back as a problem when it is not working as expected or when a new change in standard is applied.

Cheers Natt
« Last Edit: November 05, 2008, 10:48:14 AM by nattsurfaren » Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #4 on: November 07, 2008, 10:15:05 AM »

nate. sorry for the delay but i ended up in the hospital yesterday with pericarditis. I had a cold, and my heart decided it wanted in of the fun. I suggest that you never get it, because it is probably the sickest and worst I have ever felt in my life.

I use # for my delimiter btw
I assume name1 is not always the same

#Set-Cookie: (.+?)=(.+?)[;\n]#

i think that should work. i cant test it though.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #5 on: November 07, 2008, 01:38:22 PM »

nate. sorry for the delay but i ended up in the hospital yesterday with pericarditis. I had a cold, and my heart decided it wanted in of the fun. I suggest that you never get it, because it is probably the sickest and worst I have ever felt in my life.

I've no idea what that is but it sounds nasty, and rather serious - hope your feeling better.

DM
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #6 on: November 07, 2008, 04:17:45 PM »

its an inflamation of the sac around your heart. not dangerous generally by itself. But it can cause myocarditis, inflamation of the heart muscle, which can kill you fast as you can imagine.

The really dissappointing part is the drugs. There are none?!?!?! WTF!
I am taking Advil, thats it. Though it is a mega dose, that is making me feel slightly odd, but nothing fun like perc. boring!
i guess its ok, i feel like I am on drugs right now anyway.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
dink
Expert
****
Offline Offline

Posts: 349


View Profile
« Reply #7 on: November 07, 2008, 05:13:28 PM »

Damn Nuts.  That stuff is supposed to happen to us old farts.
Not you young studs.

Take care of yourself and get back on your feet soon.
Logged

[quote Nutballs]
the universe has a giant fist, and its got enough whoop ass for everyone.
[/quote]
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #8 on: November 07, 2008, 06:18:49 PM »

Nah. its actually a roll of the dice. Apparently just bad luck, and can happen at any age. Seriously sucks balls. It felt like an elephant was sitting on my chest when I laid down. And they made me lay down alot for tests... that and the 30 second switches from freezing cold to burning hot and sweating, started freaking me out a bit. until they did an EKG with me standing, and saw a perfect heart pattern, then i was a bit relieved. until the doctor said "we still need to rule out a few very very bad things in the next few minutes." LOL

But like a trooper, i answered emails from the ER bed.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
dink
Expert
****
Offline Offline

Posts: 349


View Profile
« Reply #9 on: November 07, 2008, 09:34:59 PM »

I see.  I've been told that eating fuzzies in the rain will do
that to you.  Stay outa the rain.   Grin
Logged

[quote Nutballs]
the universe has a giant fist, and its got enough whoop ass for everyone.
[/quote]
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #10 on: November 07, 2008, 11:07:03 PM »

Stupid MoFo was trying to cut a biz deal with me from the critical care unit. Angling me for an extra percent as well.

Fucking animal, that one  ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #11 on: November 08, 2008, 06:38:38 PM »

I'm sorry nutballs for what is happening to you. I really hope that you get better. You said that there are no drugs that can help you. Reading that I get it that this is permanent? I really really hope not. If so then I would try to make a big life style change and prove my doctor that it is not permanent.
Thanks for your help.
Get well.

Sincerely
Natt
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #12 on: November 09, 2008, 07:40:52 AM »

thanks natt. its generally not permanent at my age. it can be recurring though, and unfortunately, lifestyle has nothing to do with it generally. fat lazy alcoholoic drug addict has the same odds as marathon runner. go figure. So my wicked weird luck that I have balances out every once in a while, and this is one of those. could have been worse, but luck made it ONLY this.

i did find out 1 thing. I had been misdiagnosed with a defective heart valve 20 years ago. LOL
nothing is actually wrong with it.


did you try the regex?
« Last Edit: November 09, 2008, 07:50:43 AM by nutballs » Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
nattsurfaren
Journeyman
***
Offline Offline

Posts: 64


View Profile
« Reply #13 on: November 10, 2008, 02:54:43 PM »

Thanks nutballs it works fine. (after I removed the #  Wink )
 Praise
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #14 on: November 10, 2008, 04:58:35 PM »

weeee!

I am the uber regex nerd!

Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!