hi

please run step by step these addresses in address bar of one window of your browser (because addresses use of session):

1- http://support.ngsnet.net/realms.aspx?__EVENTTARGET=DataGrid1:ctl9:ctl0

2- http://support.ngsnet.net/user_sessions.aspx

3- http://support.ngsnet.net/user_sessions.aspx?EVENTTARGET=btnOK&EVENTARGUMENT=&__VIEWSTATE=dDwtNjQ5NjgwNTI1Ozs%2Bc4SsOmVzdHA4377ABboPdElmM%2FU%3D&txtUName=m5&startdate=84%2F07%2F01&enddate=86%2F06%2F31

4- http://support.ngsnet.net/sessions.aspx

every thing is ok 🙂

now i want to run all of steps with curl and get the content of last step for echo it.

any one can help me?

thanks

    this is my script:

    but it doesn't work 🙁

    i think this script cannot keep session and losed it after each step.

    <?php
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, "http://support.ngsnet.net/realms.aspx?__EVENTTARGET=DataGrid1:_ctl9:_ctl0");
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    ob_start();
    curl_exec ($curl);
    ob_end_clean();
    unset($curl);
    
    
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, "http://support.ngsnet.net/user_sessions.aspx");
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    ob_start();
    curl_exec ($curl);
    ob_end_clean();
    unset($curl);
    
    
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, "http://support.ngsnet.net/user_sessions.aspx?__EVENTTARGET=btnOK&__EVENTARGUMENT=&__VIEWSTATE=dDwtNjQ5NjgwNTI1Ozs%2Bc4SsOmVzdHA4377ABboPdElmM%2FU%3D&txtUName=m5&startdate=84%2F07%2F01&enddate=86%2F06%2F31");
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    ob_start();
    curl_exec ($curl);
    ob_end_clean();
    unset($curl);
    
    
    
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, "http://support.ngsnet.net/sessions.aspx");
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    ob_start();
    $mswdata= curl_exec ($curl);
    ob_end_clean();
    unset($curl);
    
    
    echo $mswdata;
    ?>
    

      Your session id is apparently being stored in a cookie, but your code does nothing to receive or pass back the cookie. Do this using CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE, something like this:

      $curl = curl_init(); 
      curl_setopt ($curl, CURLOPT_URL, "http://support.ngsnet.net/realms.aspx?__EVENTTARGET=DataGrid1:_ctl9:_ctl0"); 
      curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
      curl_setopt($curl, CURLOPT_HEADER, 1); 
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($curl, CURLOPT_COOKIEJAR, '/path/to/cookiefile');
      ob_start(); 
      curl_exec ($curl); 
      ob_end_clean(); 
      unset($curl); 
      
      
      $curl = curl_init(); 
      curl_setopt ($curl, CURLOPT_URL, "http://support.ngsnet.net/user_sessions.aspx"); 
      curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
      curl_setopt($curl, CURLOPT_HEADER, 1); 
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($curl, CURLOPT_COOKIEJAR, '/path/to/cookiefile');
      curl_setopt($curl, CURLOPT_COOKIEFILE, '/path/to/cookiefile');
      ob_start(); 
      curl_exec ($curl); 
      ob_end_clean(); 
      unset($curl); 
      
      
      $curl = curl_init(); 
      curl_setopt ($curl, CURLOPT_URL, "http://support.ngsnet.net/user_sessions.aspx?__EVENTTARGET=btnOK&__EVENTARGUMENT=&__VIEWSTATE=dDwtNjQ5NjgwNTI1Ozs%2Bc4SsOmVzdHA4377ABboPdElmM%2FU%3D&txtUName=m5&startdate=84%2F07%2F01&enddate=86%2F06%2F31"); 
      curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
      curl_setopt($curl, CURLOPT_HEADER, 1); 
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($curl, CURLOPT_COOKIEJAR, '/path/to/cookiefile');
      curl_setopt($curl, CURLOPT_COOKIEFILE, '/path/to/cookiefile');
      ob_start(); 
      curl_exec ($curl); 
      ob_end_clean(); 
      unset($curl); 
      
      
      
      $curl = curl_init(); 
      curl_setopt ($curl, CURLOPT_URL, "http://support.ngsnet.net/sessions.aspx"); 
      curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
      curl_setopt($curl, CURLOPT_HEADER, 1); 
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($curl, CURLOPT_COOKIEJAR, '/path/to/cookiefile');
      curl_setopt($curl, CURLOPT_COOKIEFILE, '/path/to/cookiefile');
      ob_start(); 
      $mswdata= curl_exec ($curl); 
      ob_end_clean(); 
      unset($curl); 
      
      
      echo $mswdata;

      (Untested, of course.)

      See another example here.

      Edit: I think this will work better:

      $curl = curl_init(); 
      curl_setopt($curl, CURLOPT_URL, "http://support.ngsnet.net/realms.aspx?__EVENTTARGET=DataGrid1:_ctl9:_ctl0"); 
      curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
      curl_setopt($curl, CURLOPT_HEADER, 1); 
      curl_setopt($curl, CURLOPT_COOKIEJAR, '/path/to/cookiefile');
      curl_setopt($curl, CURLOPT_COOKIEFILE, '/path/to/cookiefile');
      curl_exec($curl); 
      
      curl_setopt($curl, CURLOPT_URL, "http://support.ngsnet.net/user_sessions.aspx"); 
      curl_exec($curl); 
      
      curl_setopt($curl, CURLOPT_URL, "http://support.ngsnet.net/user_sessions.aspx?__EVENTTARGET=btnOK&__EVENTARGUMENT=&__VIEWSTATE=dDwtNjQ5NjgwNTI1Ozs%2Bc4SsOmVzdHA4377ABboPdElmM%2FU%3D&txtUName=m5&startdate=84%2F07%2F01&enddate=86%2F06%2F31"); 
      curl_exec($curl); 
      
      curl_setopt($curl, CURLOPT_URL, "http://support.ngsnet.net/sessions.aspx"); 
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
      $mswdata = curl_exec($curl); 
      echo $mswdata;

        Thanks. the second editation of your script works good.

        but the result of last url that runs with curl is different of the result of last url when we runs it handly (with internet browser which is my first post).

        may you give some minute and run both of them too see it please?

          ok i could solved this problem. thank you very very much

            Write a Reply...