Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    [Curl] Utilizzare le sessioni

    Ciao a tutti,
    utilizzando le Curl eseguo un login su una pagina remota, poi estraendo il PHPSESSION degli headers posso fare chiamate Curl seguenti utilizzando la stessa ID di Sessione.

    ora il problema..

    ..alla prima chiamata quando invio in POST login e password

    Codice PHP:
    //codice di miapagina.php (miosito.it)

    $Post[]= "CpUserCustomer=pippo";
    $Post[]= "CpPasswordCustomer=pluto";

    $UrlInit curl_init("http://www.nonmiosito.com/paginaremota.php");
    $StrPost implode("&",$Post);        
    curl_setopt($UrlInitCURLOPT_HEADER1);
    curl_setopt($UrlInitCURLOPT_POST1);
    curl_setopt($UrlInitCURLOPT_POSTFIELDS$StrPost);
    curl_setopt($UrlInitCURLOPT_FOLLOWLOCATION0);
    curl_setopt($UrlInitCURLOPT_RETURNTRANSFER1);

    $Curl curl_exec($UrlInit);
    curl_close($UrlInit); 
    quando ho fatto il login, vengono creati nelle sessioni remote (cioè su nonmiosito.com) dei valori che avrei bisogno di leggere..come posso fare?
    Credo che dovrei leggere il cookie..credo!..se fossi nella pagina paginaremota.php mi basterebbe leggere i valori in $_SESSION, ma con le Curl come potrei fare?

  2. #2

  3. #3
    ti basta leggere i cookie e rimandare poi nelle richieste successive quelli che servono
    The fastest Redis alternative ... cachegrand! https://github.com/danielealbano/cachegrand

  4. #4
    si, lo immaginavo, il problema è leggere il cookie..qui mi sono bloccato..hai un'esempio?

  5. #5
    Originariamente inviato da lbottoni
    si, lo immaginavo, il problema è leggere il cookie..qui mi sono bloccato..hai un'esempio?
    ti conviene leggere sempre i commenti, trovi TANTISSIME risposte utili

    guarda questa:
    If you're getting trouble with cookie handling in curl:

    - curl manages tranparently cookies in a single curl session
    - the option
    curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");

    makes curl to store the cookies in a file at the and of the curl session

    - the option
    curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");

    makes curl to use the given file as source for the cookies to send to the server.

    so to handle correctly cookies between different curl session, the you have to do something like this:

    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_COOKIEJAR, COOKIE_FILE_PATH);
    curl_setopt ($ch, CURLOPT_COOKIEFILE, COOKIE_FILE_PATH);

    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec ($ch);
    curl_close($ch);
    return $result;

    in particular this is NECESSARY if you are using PEAR_SOAP libraries to build a webservice client over https and the remote server need to establish a session cookie. in fact each soap message is sent using a different curl session!!

    I hope this can help someone
    Luca
    The fastest Redis alternative ... cachegrand! https://github.com/danielealbano/cachegrand

  6. #6
    letti e provati..mi dice che non permission sulla directory dei cookie.

  7. #7
    malol

    devi modificare i percorsi per farli lavorare sul tuo spazio web e comunque devi dare i permessi 777 alla cartella che conterranno questi file
    The fastest Redis alternative ... cachegrand! https://github.com/danielealbano/cachegrand

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.