Results 1 to 4 of 4

Thread: How to get a session value from browser (FF/IE)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    50
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to get a session value from browser (FF/IE)

    Hello.
    I wrote an application for data mining from a website with login/password.
    I managed to extract the info from the website but every time i have to login manually from the browser, get the PHPSESSID from the browser`s cookies info manually and put it into the application so it has access to the inner website content. Or if i use IE, i have an addon to show the headers and get the cookie info from there. Is there any way to get automatically this PHPSESSID from the browser (Firefox or InternetExplorer)?
    I tried checking the cookies.txt for Firefox but there is no info for PHPSESSID, only the other cookies. Or can i get the PHPSESSID with the program and launch the browser with the same PHPSESSID so i can be logged in with bot: the program and the browser? Or maybe i have to read browser`s memory? Or spy on the http traffic and analyze http headers and get the cookies value from the headers?
    I`m thinking about that for 2 days now and can`t get a right solution. Is there any easy way to do it? Thank you.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get a session value from browser (FF/IE)

    You must only read the incomming header and resend Session as cookie..
    http://www.qt-apps.org/content/show....?content=76432

    read ...
    Qt Code:
    1. //////////////std::cout << "Last http header respond is " << headercode << std::endl;
    2. ////////std::cout << "contentLength " << responseHeader.contentLength() << std::endl;
    3. /////////std::cout << "contentType " << qPrintable(responseHeader.contentType()) << std::endl;
    4. QStringList headerin = responseHeader.keys();
    5. for (int i = 0; i < headerin.size(); ++i) {
    6. /////////////std::cout << "" << qPrintable(headerin.at(i)) << " ->" << qPrintable(responseHeader.value(headerin.at(i))) << std::endl;
    7.  
    8. const QString HeaderValue = responseHeader.value(headerin.at(i));
    9.  
    10. if (headerin.at(i) == "content-encoding") {
    11. if (HeaderValue.contains("gzip",Qt::CaseInsensitive)) {
    12. Compressed = true;
    13. zipmode = GZIP_MODE;
    14. } else if (HeaderValue.contains("deflate",Qt::CaseInsensitive)) {
    15. Compressed = true;
    16. zipmode = DEFLATE_MODE;
    17. } else if (HeaderValue.contains("qcompress",Qt::CaseInsensitive)) {
    18. Compressed = true;
    19. zipmode = QT_MODE;
    20. }
    21. }
    22. if (headerin.at(i) == "set-cookie") {
    23. if (!CookieList.contains(HeaderValue,Qt::CaseInsensitive)) {
    24. CookieList.append( HeaderValue );
    25. }
    26. }
    27.  
    28.  
    29. void Communicator::SaveData(const QHttpResponseHeader &responseHeader )
    30. {
    31. headercode = lastResponse().statusCode();
    32. QStringList headerin = responseHeader.keys();
    33. headerresponder =""; //// headerin.join("\n");
    34. qDebug() << "### headerin " << headerin;
    35.  
    36. HeaderIncome.clear();
    37. for (int i = 0; i < headerin.size(); ++i) {
    38. const QString HeaderValue = responseHeader.value(headerin.at(i));
    39. //////qDebug() << "### HeaderValue " << HeaderValue;
    40. HeaderIncome.insert(headerin.at(i),HeaderValue);
    41. headerresponder.append(QString("%1=%2\n").arg(headerin.at(i)).arg(HeaderValue));
    42. }
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 

    resend CookieList

    Qt Code:
    1. void AppendHeader( const QString nam , const QString val )
    2. {
    3. /* QHttpRequestHeader header;
    4.  */
    5. ///////////std::cout << "### Send cookie ->" << qPrintable(val) << std::endl;
    6. header.setValue(nam,val);
    7. }
    To copy to clipboard, switch view to plain text mode 

    http://fop-miniscribus.googlecode.co...mmunicator.cpp

    IMO: is not code from shool ... but its run..

  3. #3
    Join Date
    Feb 2008
    Posts
    50
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get a session value from browser (FF/IE)

    Yes, i know how to extract the cookie from the header and sent it again, but only my program will have the session and browse the website. What i want is... my program to have the session AND my browser to have the session. So while my program searches the page, i can browse with Firefox and watch the other things. Do you have solution for that?

  4. #4
    Join Date
    Feb 2008
    Posts
    50
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get a session value from browser (FF/IE)

    I think i got a solution. I compiled a simple console proxy server transparently forwarding all the http requests and i`ll try to run it with QProcess and read the http headers from the output. The browser proxy settings, i`ll try to set automatically from my program.

    Also, i found that Firefox keeps the session ID into sessions.js in the profile`s folder.
    But i can`t find where IE keeps it...

Similar Threads

  1. Query @ SESSION
    By ashukla in forum General Programming
    Replies: 3
    Last Post: 15th May 2008, 11:19
  2. Replies: 7
    Last Post: 14th March 2008, 13:52
  3. Invoking a browser...???
    By deepusrp in forum Newbie
    Replies: 4
    Last Post: 12th June 2007, 17:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.