What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help] dealing with cookies

[Help] dealing with cookies
Author: Message:
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: [Help] dealing with cookies
It shouldnt be that hard Im guessing your trying to login so in my example ill do a post request then get the cookie header


this example should log you onto this forum and show all Trashing and testing threads (which you need to be logged in to see)
code:
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var cookies;

login("username", "password", getTandT);


function getTandT(){
    xmlhttp.open("GET", "http://shoutbox.menthix.net/forumdisplay.php?fid=18", true);
    xmlhttp.setRequestHeader("Cookie" , cookies.join(";") )
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState==4) {
            if(xmlhttp.status == 200){
                //look its T and T's source :D
                //Debug.Trace(xmlhttp.responseText);
               
                //show all threads
                var threads = xmlhttp.responseText.match(/<a href="showthread.php\?tid=([0-9]+)">([^<]*)<\/a>/g);
                for(var i=0;i<threads.length;i++){
                    Debug.Trace(threads[i].match(/<a href="showthread.php\?tid=([0-9]+)">([^<]+)<\/a>/)[2])
                }
            }
        }
    }

    xmlhttp.send();

}


function login(username , password , callback){
    xmlhttp.open("POST", "http://shoutbox.menthix.net/member.php", true);
    //set the request header for post
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   
   
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState==4) {
            if(xmlhttp.status == 200){
                cookies = get_cookies(xmlhttp.GetAllResponseHeaders());
                callback();
            }
        }
    }
   
    xmlhttp.send("username=" + escape(username) + "&password=" + escape(password) + "&action=do_login");
}



//sometimes the Set-Cookie header is sent twice and getResponseHeader only reads the first... so we have to join it ourselfs :(
function get_cookies(headers){
    var header = headers.split("\r\n");
    var cookies = [];
    for(var i=0;i<header.length;i++){
        var type = header[i].match(/^Set-Cookie: (.*)$/);
        if(type){
            cookies.push(type[1]);
        }
    }
    return cookies;
}


[Image: dt2.0v2.png]      Happy Birthday, WDZ
07-14-2006 07:25 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Help] dealing with cookies - by BstrdSmkr on 07-14-2006 at 01:39 AM
RE: [Help] dealing with cookies - by -dt- on 07-14-2006 at 07:25 AM
RE: [Help] dealing with cookies - by BstrdSmkr on 07-17-2006 at 03:56 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On