Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8931549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:08:17+00:00 2026-06-15T09:08:17+00:00

A few days ago I decided to write a short script. It makes two

  • 0

A few days ago I decided to write a short script. It makes two GET requestes to an ASP server, because I want to get the sessionId variable and the viewstate variable.
I decided to use fsockopen() and it works until the first request! After that it crashes and there’s a Bad request error.

Here’s the code:

<?php
$fp = fsockopen("www.atb.bergamo.it", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {

    $out = "GET /ITA/Default.aspx?SEZ=2&PAG=38&MOD=LINTRV HTTP/1.1\r\n";
    $out .= "Host: www.atb.bergamo.it\r\n";
    $out .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2\r\n";
    $out .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
    $out .= "Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
    $out .= "Accept-Encoding: gzip, deflate\r\n";
    $out .= "Connection: keep-alive\r\n\r\n";
    fwrite($fp, $out);


    $header = '';

    do{
        $header .= fgets($fp, 128);
    }while(strpos($header, "\r\n\r\n") == false);

    list(,$sessione) = explode('ASP.NET_SessionId=', $header);
    list($sessione) = explode('; path=/; HttpOnly', $sessione);

    $cookie = "Cookie: ASP.NET_SessionId=".$sessione."; READONLY=MA==; __utma=".$_COOKIE['__utma']."; __utmb=".$_COOKIE['__utmb']."; __utmc=".$_COOKIE['__utmc']."; __utmz=".$_COOKIE['__utmz']."; HstCfa1041967=".$_COOKIE['HstCfa1041967']."; HstCla1041967=".$_COOKIE['HstCla1041967']."; HstCmu1041967=".$_COOKIE['HstCmu1041967']."; HstPn1041967=".$_COOKIE['HstPn1041967']."; HstPt1041967=".$_COOKIE['HstPt1041967']."; HstCnv1041967=".$_COOKIE['HstCnv1041967']."; HstCns1041967=".$_COOKIE['HstCns1041967']."; c_ref_1041967=http%3A%2F%2Fwww.google.it%2Furl%3Fsa%3Dt%26rct%3Dj%26q%3Datb%2520orari%26source%3Dweb%26cd%3D1%26sqi%3D2%26ved%3D0CC4QFjAA%26url%3Dhttp%253A%252F%252Fwww.atb.bergamo.it%252FITA%252FDefault.aspx%253FSEZ%253D2%2526PAG%253D38%2526MOD%253DLINTRV%26ei%3DxZi3UNK4AojysgburIGoCg%26usg%3DAFQjCNFKu0Tuffg6uZVhC1akh3TKqesWcQ;"; // __atuvc=27%7C48

    $cookie = str_replace("utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(none)", "utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=atb", $cookie);


    echo "</br></br></br></br> ci sono </br></br></br></br>";
    $out =  "GET /ITA/Default.aspx?SEZ=2&PAG=38&MOD=LINTRV HTTP/1.1\r\n";
    $out .= "Host: www.atb.bergamo.it\r\n";
    $out .= "Host: www.atb.bergamo.it\r\n";
    $out .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2\r\n";
    $out .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
    $out .= "Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
    $out .= "Accept-Encoding: gzip, deflate\r\n";
    $out .= "Connection: keep-alive\r\n";
    $out .= $cookie."\r\n\r\n";

    fwrite($fp, $out);

    while (!feof($fp)) {
        echo fgets($fp, 128);
    }       

    //die($header."</br></br></br></br>".$sessione);

    fclose($fp);
}

?>

I run the script on a local server, server2go. I don’t know why it doesn’t work…
Can you help me please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:08:18+00:00Added an answer on June 15, 2026 at 9:08 am

    Use curl

    $url = "http://www.atb.bergamo.it/ITA/Default.aspx?SEZ=2&PAG=38&MOD=LINTRV";
    $ckfile = tempnam ("/tmp", "CURLCOOKIE");
    $ch = curl_init ($url);
    curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    $html = curl_exec ($ch);
    
    curl_close($ch);
    
    preg_match('~<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" />~',$html,$viewstate);
    
    
    var_dump(file_get_contents($ckfile)); <--- cookie
    var_dump($viewstate[1]);              <--- View State
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A few days ago I installed tomcat 7 and decided to try building a
few days ago i asked about how to get all running processes in the
few days ago i read tutorial about GenericRepository and Unit Of Work patterns http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
A few days ago I set up a small development server. Running on Windows
So far I have worked in the console and a few days ago decided
I have decided to learn (Common) Lisp a few days ago and I realize
A few days ago I started with Ubuntu for the first time. I want
A few days ago the push notification for Android devices was working fine because
I lost my temper few days ago because of this simple problem. Can you
So a few days ago I decided I would try and learn Ruby and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.