🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.javascript
2 messages
2 total messages Started by maYk Mon, 28 Mar 2011 13:28
Cookie w javascript
#50691
Author: maYk
Date: Mon, 28 Mar 2011 13:28
59 lines
3242 bytes
Witajcie, probuje napisac aplikacje pod PHP przy uzyciu curl ktora
bedzie emulowala zachowanie uzytkownika. Chodzi o system pomocy
technicznej w portalu salesforce.com. Chce aby moj system byl w stanie
wypelnic ich formularz i przeslac go poprawnie do strony ktora utworzy
nowy ticket. Poradzilem sobie z logowaniem i przechodzeniem z
podstrony na podstrone. Problem tkwi jednak w formularzu ktory w jakis
sposob przy pomocy javascript tworzy jakas magie przez co dane z
formularza na kolejnej stronie nie sa rozpoznawane. Ponizej kod ktory
wedlug mnie za to odpowiada. Jak moge sobie z tym poradzic jesli
wtyczka curl ktora uzywam, nie obsluguje javascript?

var ClientHash = function(){}

ClientHash.prototype.putClientHash = function(name, value, domain,
path, secure) {
    document.cookie = name + '=' + value +
	    ((domain) ? '; domain=' + domain : '') +
        ((path) ? '; path=' + path : '; path=/') +
        ((secure) ? '; Secure' : '');
}


ClientHash.prototype.getClientHash = function(name) {
    var dc = document.cookie;
    var prefix = name + '=';
    var begin = dc.indexOf('; ' + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(';', begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

ClientHash.prototype.needsClientHash = function(hashName, hashValue,
clientSrc, nextPage) {

    var clientHash = ClientHash.prototype.getClientHash(hashName);

    var needsClientHash = clientHash == hashValue;

    if (!needsClientHash) {
        var currLoc = unescape(window.location.href);
        var index = currLoc.indexOf(hashValue, 0);
        needsClientHash = index > -1;
    }

    if (!needsClientHash) {
        window.location.href = nextPage + '&winLoc=' + window.location
+ '&c=' + clientHash + '&s=' + hashValue + '&cs=' + clientSrc;
    }

    return needsClientHash;
}
Re: Cookie w javascript
#50692
Author: Manhattan Project
Date: Tue, 29 Mar 2011 06:36
32 lines
2198 bytes
Przyznaję, że nie czytałem javascript... ale jeżeli jesteś w stanie
wydobyć z wygenerowanej strony zawartość cookie (a powinieneś móc), to
sprawa jest już prosta:

	    $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "{$adres_celu}");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            $output = curl_exec ($ch);
            $cookie = // tutaj funkcja, która wydobędzie ze zmiennej
output zawartość ciasteczka

potem


            $header = array(
                "Cookie: {$cookie}"// i ew. inne typu  "Authorization:
Basic YCftaW46VkkuNj01LaasEsg=="
            );
            curl_setopt($ch, CURLOPT_URL, "{$adres_celu}");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            $output = curl_exec ($ch);

MP
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads