PDA

View Full Version : How to get a session value from browser (FF/IE)


sadjoker
24th May 2008, 14:18
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.

patrik08
27th May 2008, 09:51
You must only read the incomming header and resend Session as cookie..
http://www.qt-apps.org/content/show.php/Http+Debugger++qt4.3.3?content=76432

read ...

//////////////std::cout << "Last http header respond is " << headercode << std::endl;
////////std::cout << "contentLength " << responseHeader.contentLength() << std::endl;
/////////std::cout << "contentType " << qPrintable(responseHeader.contentType()) << std::endl;
QStringList headerin = responseHeader.keys();
for (int i = 0; i < headerin.size(); ++i) {
/////////////std::cout << "" << qPrintable(headerin.at(i)) << " ->" << qPrintable(responseHeader.value(headerin.at(i))) << std::endl;

const QString HeaderValue = responseHeader.value(headerin.at(i));

if (headerin.at(i) == "content-encoding") {
if (HeaderValue.contains("gzip",Qt::CaseInsensitive)) {
Compressed = true;
zipmode = GZIP_MODE;
} else if (HeaderValue.contains("deflate",Qt::CaseInsensitive)) {
Compressed = true;
zipmode = DEFLATE_MODE;
} else if (HeaderValue.contains("qcompress",Qt::CaseInsensitive)) {
Compressed = true;
zipmode = QT_MODE;
}
}
if (headerin.at(i) == "set-cookie") {
if (!CookieList.contains(HeaderValue,Qt::CaseInsensit ive)) {
CookieList.append( HeaderValue );
}
}


void Communicator::SaveData(const QHttpResponseHeader &responseHeader )
{
headercode = lastResponse().statusCode();
QStringList headerin = responseHeader.keys();
headerresponder =""; //// headerin.join("\n");
qDebug() << "### headerin " << headerin;

HeaderIncome.clear();
for (int i = 0; i < headerin.size(); ++i) {
const QString HeaderValue = responseHeader.value(headerin.at(i));
//////qDebug() << "### HeaderValue " << HeaderValue;
HeaderIncome.insert(headerin.at(i),HeaderValue);
headerresponder.append(QString("%1=%2\n").arg(headerin.at(i)).arg(HeaderValue));
}

}




resend CookieList


void AppendHeader( const QString nam , const QString val )
{
/* QHttpRequestHeader header;
*/
///////////std::cout << "### Send cookie ->" << qPrintable(val) << std::endl;
header.setValue(nam,val);
}




http://fop-miniscribus.googlecode.com/svn/trunk/http_debugger.1.0/communicator.cpp

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

sadjoker
28th May 2008, 19:35
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?

sadjoker
29th May 2008, 00:45
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...