Help me to use PHP curl

Discussion in 'PHP' started by balasun, Apr 11, 2009.

  1. #1
    Hello all,

    I am using PHP curl function to login in secure server site by post the parameters.

    My code is as follows:

    
    cookie_jar = tempnam('tmp/','cookie');
    
    $url = "https://nameos site/login";
    $POSTFIELDS = 'session_key=emailid&session_password=password&session_login=&session_rikey=invalid key';
    $reffer = "http://www.securesitename.com";
    $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
    $cookie_file_path = "tmp/";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_REFERER, $reffer);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    echo $result = curl_exec($ch);
    exit;
    
    curl_close($ch);
    
    
    PHP:
    But the login does not done. Pls help me to do login.. Is any special parameters need when we use CURL for secured site?

    Thanks,
     
    balasun, Apr 11, 2009 IP
  2. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #2
    Why to use exit before you've closed curl ? :confused:
     
    ActiveFrost, Apr 11, 2009 IP
  3. ghprod

    ghprod Active Member

    Messages:
    1,010
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #3
    try to remove exit function first :)

    regards
     
    ghprod, Apr 12, 2009 IP
  4. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #4
    echo is used before exit so it will have no effect on echo.

    Can u tell us the site, then may be I can help you :)
     
    harrisunderwork, Apr 13, 2009 IP
  5. antigravity

    antigravity Active Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #5
    What result to you actually get from the above code? Bad username/password? Does it look like your secure page reads the parameters you post?
     
    antigravity, Apr 13, 2009 IP