View Single Post

 
Old 07-13-2007, 03:07 PM
r0manoff <b>Offline</b>
Junior Member
 
Join Date: Jul 2007
Posts: 1
Thank you Chad for such a useful functions and support for beginners.

I have 2 main problems now.

1. The login doesnt work.
I was trying to detect the error, and I think it is because the cookie file keeps being empty. I have the test files on a XAMPP directory on my desktop PC, with WinXP SP2, on a NTFS partition. I have Administrative privileges. As you will see, I open 2 files, one for error reporting and the other one for cookies. The error reporting file is being opened without problems by curl, because I give it a handle to an open file. However for cookies I give a filename, so I dont know if curl can write to that file.

2. The images on the target site have relative paths, so they wont show on my browser via curl. I think this is not so difficult to fix, but I am new to curl, so please enlighten me where should I look for a solution.


Besides, I would like to know if it is possible to give curl a variable instead of a filename for cookie options. Because I would like to redirect the cookies to the end user, instead of storing them on the server. Something like this:

SITE ---- [login_cookie]----> PHP/CURL setrawcookie() ---- [login_cookie] ----> END USER



Thank you very much again, I would appreciate a lot if you can give me some advice.

Roman.

Here is my test code:
PHP Code:
<?php
define
(DEBUG_MODETRUE);
error_reporting(E_ALL E_STRICT);


$my_mundo_travian 'http://s1.travian.net';
$my_login_url "$my_mundo_travian/dorf1.php";

/* below the original test page has a string with valid header data copied as
    shown in the tutorial using live http headers */
$my_login_data "";
$my_proxy '';
$my_proxy_status 'off';

/* after a successful login, this url shows the initial game control panel.
    If login fails, it shows the login page */
$my_grab_page 'http://s1.travian.net/dorf1.php';

$fp_err fopen("curl_errors.txt""w");
curl_login($my_login_url$my_login_data$my_proxy$my_proxy_status);
echo 
curl_grab_page($my_grab_page$my_proxy$my_proxy_status);
fclose($fp_err);


/* login functions by Chad from http://codersshack.com/forums/php_11/tutorial-curl-login_44.html */
/* functions are slightly modified in order to send curl verbose report to a file */

function curl_login($url,$data,$proxy,$proxystatus){
    global 
$fp_err;

    
$fp fopen("cookie_travian.txt""w");
    
fclose($fp);
    
$login curl_init();
    if (
DEBUG_MODE) {
      
curl_setopt($loginCURLOPT_VERBOSETRUE);
      
curl_setopt($loginCURLOPT_STDERR$fp_err);
    }
    
curl_setopt($loginCURLOPT_COOKIEJAR"cookie_travian.txt");
    
curl_setopt($loginCURLOPT_COOKIEFILE"cookie_travian.txt");
    
curl_setopt($loginCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4");
    
curl_setopt($loginCURLOPT_REFERER"http://s1.travian.net/dorf1.php");
    
curl_setopt($loginCURLOPT_TIMEOUT30);
    
curl_setopt($loginCURLOPT_RETURNTRANSFERTRUE);
    if (
$proxystatus == 'on') {
        
curl_setopt($loginCURLOPT_SSL_VERIFYHOSTFALSE);
        
curl_setopt($loginCURLOPT_HTTPPROXYTUNNELTRUE);
        
curl_setopt($loginCURLOPT_PROXY$proxy);
    }
    
curl_setopt($loginCURLOPT_URL$url);
    
curl_setopt($loginCURLOPT_HEADERTRUE);
    
curl_setopt($loginCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT']);
    
curl_setopt($loginCURLOPT_FOLLOWLOCATIONTRUE);
    
curl_setopt($loginCURLOPT_POSTTRUE);
    
curl_setopt($loginCURLOPT_POSTFIELDS$data);
    
ob_start();      // prevent any output
    
return curl_exec ($login); // execute the curl command
    
ob_end_clean();  // stop preventing output
    
curl_close ($login);
    unset(
$login);    
}                  

function 
curl_grab_page($site,$proxy,$proxystatus){
    global 
$fp_err;

    
$ch curl_init();
    if (
DEBUG_MODE) {
      
curl_setopt($chCURLOPT_VERBOSETRUE);
      
curl_setopt($chCURLOPT_STDERR$fp_err);
    }
    
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
    if (
$proxystatus == 'on') {
        
curl_setopt($chCURLOPT_SSL_VERIFYHOSTFALSE);
        
curl_setopt($chCURLOPT_HTTPPROXYTUNNELTRUE);
        
curl_setopt($chCURLOPT_PROXY$proxy);
    }
    
curl_setopt($chCURLOPT_COOKIEFILE"cookie_travian.txt");
    
curl_setopt($chCURLOPT_URL$site);
    
ob_start();      // prevent any output
    
return curl_exec ($ch); // execute the curl command
    
ob_end_clean();  // stop preventing output
    
curl_close ($ch);
}

?>
here is what i get in the curl log file "curl_errors.txt":
Quote:
Originally Posted by curl_errors.txt
* About to connect() to s1.travian.net port 80 (#0)
* Trying 88.198.59.126... * connected
* Connected to s1.travian.net (88.198.59.126) port 80 (#0)
> GET /dorf1.php HTTP/1.1
Host: s1.travian.net
Accept: */*

< HTTP/1.1 200 OK
< Date: Fri, 13 Jul 2007 21:36:52 GMT
< Server: Apache
< X-Powered-By: PHP/5.2.1
< Expires: Mon, 26 Jul 1997 05:00:00 GMT
< Last-Modified: Fri, 13 Jul 2007 21:36:52 GMT
< Cache-Control: no-store, no-cache, must-revalidate
< Cache-Control: post-check=0, pre-check=0
< Pragma: no-cache
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
* Closing connection #0
che, must-revalidate
< Cache-Control: post-check=0, pre-check=0
< Pragma: no-cache
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
* Closing connection #0

Last edited by r0manoff; 07-13-2007 at 03:26 PM.
Reply With Quote