Bouts de Codes PHP

Récupération des données adsense et affichage de statistiques

Information sur le code source PHP

Ecrit par :  forty
Site de l'auteur Voir
Codes en PHP de l'auteur : [19] sources Voir
Enregistrement le 23 Juil 2008 - Vu 2531 fois
Impression: Imprimer le code
Pas encore
de vote

Description du code source

Information sur le code source

Ce script permet de récupérer les données adsense grâce à une classe php. Les données récupérées sont le nombre d'impressions de page, le nombre de clics, le CTR de la page, l'eCPM de la page et le revenus.

Ce script de téléchargement des données adsense contient également un petit exemple. Une première série de donnée affiche le résultat du jour, de la veille, du mois courant et du mois dernier. Une petit calcul affiche également la moyenne par jour du mois courant ainsi qu'une prévision des données du mois courant par extrapolation. Le premier du mois seul les données du jour, de la veille et du mois dernier sont affichées.

Il ne faut pas oublier de renseigner l'email et le mot de passe adsense!

Code Source



.01
.02
.03
.04
.05
.06
.07
.08
.09
.10
.11
.12
.13
.14
.15
.16
.17
.18
.19
.20
.21
.22
.23
.24
.25
.26
.27
.28
.29
.30
.31
.32
.33
.34
.35
.36
.37
.38
.39
.40
.41
.42
.43
.44
.45
.46
.47
.48
.49
.50
.51
.52
.53
.54
.55
.56
.57
.58
.59
.60
.61
.62
.63
.64
.65
.66
.67
.68
.69
.70
.71
.72
.73
.74
.75
.76
.77
.78
.79
.80
.81
.82
.83
.84
.85
.86
.87
.88
.89
.90
.91
.92
.93
.94
.95
.96
.97
.98
.99
.100
.101
.102
.103
.104
.105
.106
.107
.108
.109
.110
.111
.112
.113
.114
.115
.116
.117
.118
.119
.120
.121
.122
.123
.124
.125
.126
.127
.128
.129
.130
.131
.132
.133
.134
.135
.136
.137
.138
.139
.140
.141
.142
.143
.144
.145
.146
.147
.148
.149
.150
.151
.152
.153
.154
.155
.156
.157
.158
.159
.160
.161
.162
.163
.164
.165
.166
.167
.168
.169
.170
.171
.172
.173
.174
.175
.176
.177
.178
.179
.180
.181
.182
.183
.184
.185
.186
.187
.188
.189
.190
.191
.192
.193
.194
.195
.196
.197
.198
.199
.200
.201
.202
.203
.204
.205
.206
.207
.208
.209
.210
.211
.212
.213
.214
.215
.216
.217
.218
.219
.220
.221
.222
.223
.224
.225
.226
.227
.228
.229
.230
.231
.232
.233
.234
.235
.236
.237
.238
.239
.240
.241
.242
.243
.244
.245
.246
.247
.248
.249
.250
.251
.252
.253
.254
.255
.256
.257
.258
.259
.260
.261
.262
.263
.264
.265
.266
.267
.268
.269
.270
.271
.272
.273
.274
.275
.276
.277
.278
.279
.280
.281
.282
.283
.284
.285
.286
.287
.288
.289
.290
.291
.292
.293
.294
.295
.296
.297
.298
.299
.300
.301
.302
.303
.304
.305
.306
.307
.308
.309
.310
.311
.312
.313
.314
.315
.316
.317
.318
.319
.320
.321
.322
.323
.324
.325
.326
.327
.328
.329
.330
.331
.332
.333
.334
.335
.336
.337
.338
.339
.340
.341
.342
.343
.344
.345
.346
.347
.348
.349
.350
.351
.352
.353
.354
.355
.356
.357
.358
.359
.360
.361
.362
.363
.364
.365
.366
.367
.368
.369
.370
.371
.372
.373
.374
.375
.376
.377
.378
.379
.380
.381
.382
.383
.384
.385
.386
.387
.388
.389
.390
.391
.392
.393
.394
.395
.396
.397
.398
.399
.400
.401
.402
.403
.404
.405
.406
.407
.408
.409
.410
.411
.412
.413
.414
.415
.416
.417
.418
.419
.420
.421
.422
.423
.424
.425
.426
.427
.428
 

<?php
/******************************************************************************/
/*                                                                            */
/*                       __        ____                                       */
/*                 ___  / /  ___  / __/__  __ _____________ ___               */
/*                / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-<               */
/*               / .__/_//_/ .__/___/\___/\_,_/_/  \__/\__/___/               */
/*              /_/       /_/                                                 */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/*                                                                            */
/* Titre          : Récupération des données adsense et affichage de...       */
/*                                                                            */
/* URL            : http://www.phpsources.org/scripts431-PHP.htm              */
/* Auteur         : forty                                                     */
/* Date édition   : 23 Juil 2008                                              */
/* Website auteur : http://www.toplien.fr/                                    */
/*                                                                            */
/******************************************************************************/

define('ADSENSE_TODAY''https://www.google.com/adsense/report/overview?timePeriod=today');
define('ADSENSE_YESTERDAY''https://www.google.com/adsense/report/overview?timePeriod=yesterday');
define('ADSENSE_LASTMONTH''https://www.google.com/adsense/report/overview?timePeriod=lastmonth');
define('ADSENSE_THISMONTH''https://www.google.com/adsense/report/overview?timePeriod=thismonth');
define('ADSENSE_LAST7DAYS''https://www.google.com/adsense/report/overview?timePeriod=last7days');
define('ADSENSE_SINCELASTPAYMENT''https://www.google.com/adsense/report/overview?timePeriod=sincelastpayment');

$email "votre@email.adsense";
$password "Votre_mot_de_passe_adsense";

function arrondi_mnt_taux($montant$taux) {
    if ($taux) {
        return round($montant $taux2);
    } else {
        return '';
    }
}

class AdSense {
    var $curl null;
    var $cur_url null;

    function AdSense(){
        $this->curl curl_init();
        $cookie ".";
        $this->my_curl_setopt(CURLOPT_HEADERfalse);
        $this->my_curl_setopt(CURLOPT_RETURNTRANSFERtrue);
        $this->my_curl_setopt(CURLOPT_SSL_VERIFYPEERfalse);
        $this->my_curl_setopt(CURLOPT_SSL_VERIFYHOSTfalse);
        $this->my_curl_setopt(CURLOPT_FOLLOWLOCATIONtrue);
        $this->my_curl_setopt(CURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
        $this->my_curl_setopt(CURLOPT_COOKIEFILE$cookie);
        $this->my_curl_setopt(CURLOPT_COOKIEJAR$cookie);

        register_shutdown_function(array(&$this'__destructor'));
    }

    function connect($email$password){
        // phase 1
        $this->cur_url  'https://www.google.com/accounts/ServiceLoginBox';
        $this->cur_url .= '?service=adsense&ltmpl=login&ifr=true&rm=hide&fpui=3'
;
        $this->cur_url .= '&nui=15&alwf=true&passive=true';
        $this->cur_url .= 
'&continue=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth';
        $this->cur_url .= 
'&followup=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&hl=fr';
        $this->my_curl_setopt(CURLOPT_URL$this->cur_url);
        $result $this->my_curl_exec();
        preg_match_all(
'<input[[:blank:]]+type="hidden"[[:blank:]]+name="(.*?)"[[:blank:]]+value="(.' .
'*?)">', 
                             $result$out);
        $params = array();
        foreach($out[1] as $key=>$name) { $params[] = $name '=' urlencode(
$out[2][$key]); }
        $params[] = 'Email=' urlencode($email);
        $params[] = 'Passwd=' urlencode($password);
        $params[] = 'submit=' urlencode('Connexion');

        // phase 2
        $this->cur_url "https://www.google.com/accounts/ServiceLoginBoxAuth?" 
join('&'$params);
        $this->my_curl_setopt(CURLOPT_URL"https://www.google.com/accounts/ServiceLoginBoxAuth");
        $this->my_curl_setopt(CURLOPT_POSTtrue);
        $this->my_curl_setopt(CURLOPT_POSTFIELDSjoin('&'$params));
        $result $this->my_curl_exec();
        if (preg_match("/.*<a href=\"(.*)\" target=\"_top\">/"$result$matches)) {
            // phase 3
            $this->cur_url str_replace('&amp;''&'$matches[1]);
            curl_setopt($this->curlCURLOPT_POSTfalse);
            curl_setopt($this->curlCURLOPT_URL$this->cur_url);
        } else {
            die("Impossible de récupérer l'url de redirection :<br>" nl2br(
htmlspecialchars($result)));
        }

        $result $this->my_curl_exec();
        if (preg_match(
"/<meta http-equiv=\"refresh\" content=\"0; url=&#39;(.*)&#39;\">/si"$result$matches )) {
            // phase 4
            $this->cur_url htmlspecialchars_decode($matches[1]);
            $this->my_curl_setopt(CURLOPT_URL$this->cur_url);
            $result $this->my_curl_exec();
        } else {
            die("Impossible de récupérer l'url de redirection :<br>" nl2br(
htmlspecialchars($result)));
        }

        // did we login ?
        if (preg_match('/(' preg_quote('/adsense/signout''/') . '|' preg_quote('/adsense/gaialogout''/') . ')/',  $result)) {
            return true;
        } else {
            //echo htmlspecialchars($result);
            return false;
        }
    }

    function today(){
        $this->my_curl_setopt(CURLOPT_URLADSENSE_TODAY);
        return $this->parse($this->my_curl_exec());
    }

    function yesterday(){
        $this->my_curl_setopt(CURLOPT_URLADSENSE_YESTERDAY);
        return $this->parse($this->my_curl_exec());
    }

    function last7days(){
        $this->my_curl_setopt(CURLOPT_URLADSENSE_LAST7DAYS);
        return $this->parse($this->my_curl_exec());
    }

    function lastmonth(){
        $this->my_curl_setopt(CURLOPT_URLADSENSE_LASTMONTH);
        return $this->parse($this->my_curl_exec());
    }

    function thismonth(){
        $this->my_curl_setopt(CURLOPT_URLADSENSE_THISMONTH);
        return $this->parse($this->my_curl_exec());
    }

    function sincelastpayment(){
        $this->my_curl_setopt(CURLOPT_URLADSENSE_SINCELASTPAYMENT);
        return $this->parse($this->my_curl_exec());
    }

    function __destructor(){
        $this->my_curl_close();
    }

    private function parse($content){
        if (!preg_match_all(
'/<td nowrap valign="top" style="text-align:right" class="">(.*?)<\/td>/', 
                                  $content$matches1)) {
            echo 'Pas de détail pour :<br>' .  nl2br(htmlspecialchars($content))
 . '<br>';
            $matches1[1][] = '';
            $matches1[1][2] = '';
            $matches1[1][3] = '';
            $matches1[1][4] = '';
        }
        if (!preg_match(
'/\<td style\="font-weight\:bold;"' .
' nowrap\>([0-9,]+)&nbsp;\$US\<\/td\>\<\/tr\>\<\/tfoot\>\<\/table\>/', 
                             $content$matches2)) {
            echo 'Pas de total pour :<br>' .  nl2br(htmlspecialchars($content)) 
. '<br>';
            $matches2[1] = '';
        }
        if (!preg_match(
'/\<span style\="color\:green;"\>([0-9,]+)&nbsp;\$US&nbsp;\<\/span\>\<\/h1\>/', 
                             $content$matches3)) {
            echo 'Pas de revenus du jour pour :<br>' .  nl2br(htmlspecialchars(
$content)) . '<br>';
            $matches3[1] = '';
        }

        return array(
            "impressions" => preg_replace('/[^0-9]/'''$matches1[1][]),
            "clicks" => preg_replace('/[^0-9]/'''$matches1[1][1]),
            "ctr" => $matches1[1][2],
            "ecpm" => $matches1[1][3],
            "earnings" => $matches1[1][4],
            "total" => str_replace(',''.'$matches2[1]),
            "jour" => str_replace(',''.'$matches3[1])
        );
    }

    private function my_curl_init() {
        if (($this->curl curl_init()) === false) {
            $num_erreur curl_errno($this->curl);
            $text_erreur curl_error($this->curl);
            die(
"<font color=\"red\">Erreur d'initialisation de la session cURL : $num_erreur" .
" : $text_erreur</font>");
        }
    }

    private function my_curl_setopt($param$value) {
        if (!curl_setopt($this->curl$param$value)) {
            $num_erreur curl_errno($this->curl);
            $text_erreur curl_error($this->curl);
            die(
"<font color=\"red\">Erreur d'ajout de l'option cURL $param pour " $this->
cur_url . 
                 " : $num_erreur : $text_erreur</font>");
        }
    }

    private function my_curl_exec() {
        if (($result curl_exec($this->curl)) === false) {
            $num_erreur curl_errno($this->curl);
            $text_erreur curl_error($this->curl);
            die("<font color=\"red\">Erreur d'exécution cURL pour " $this->
cur_url . 
                 " : $num_erreur : $text_erreur</font>");
        }
        $http_code curl_getinfo($this->curlCURLINFO_HTTP_CODE);
        if (($http_code <> 200) && ($http_code <> 301) && ($http_code <> 302)) {
            $url_reelle curl_getinfo($this->curlCURLINFO_EFFECTIVE_URL);
            die(
"<font color=\"red\">Code retour $http_code pour $url_reelle</font>");
        }
        return $result;
    }

    private function my_curl_close() {
        curl_close($this->curl);
    }
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Revenus adsense</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
// code venant de :
// http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html#dev
$XMLContentfile("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
);
//the file is updated daily between 14:15 and 15:00 CET
$taux = ;
foreach ($XMLContent as $line) {
    if (ereg("currency='([[:alpha:]]+)'"$line$currencyCode)) {
        if (ereg("rate='([[:graph:]]+)'"$line$rate)) {
            if ($currencyCode[1] == 'USD') {
                $taux $rate[1];
            }
        }
    }
}
$adsense = new AdSense();
if ($adsense->connect($email$password)) {
    $day date('j');
    if (($day == 1) && (date('G') >= 9)) { //nous sommes le 1er du mois
        $yesterday $adsense->yesterday();
        $today $adsense->today();
        $lastmonth $adsense->lastmonth();
        echo '<table border="1">';
        echo '<tr><td></td><td><strong>Impressions</strong></td>';
        echo '<td><strong>Clics</strong></td>';
        echo '<td><strong>CTR</strong></td>';
        echo '<td><strong>eCPM</strong></td>';
        echo '<td><strong>CPC</strong></td>';
        echo '<td colspan="2"><strong>Montant total</strong></td></tr>';
        echo '<tr><td><strong><a href="' htmlspecialchars(ADSENSE_YESTERDAY) .
 '">Hier</a></strong></td>';
        echo '<td>' $yesterday['impressions'] . '</td>';
        echo '<td>' $yesterday['clicks'] . '</td>';
        echo '<td>' $yesterday['ctr'] . '</td>';
        echo '<td>' $yesterday['ecpm'] . '</td>';
        echo '<td>' arrondi_mnt_taux($yesterday['total'], $yesterday['clicks']
) . ' $US</td>';
        echo '<td>' $yesterday['total'] . ' $US</td>';
        echo '<td>' arrondi_mnt_taux($yesterday['total'], $taux) . 
' &euro;</td></tr>';
        echo '<tr><td><strong><a href="' htmlspecialchars(ADSENSE_TODAY) . 
'">Aujourd\'hui</a></strong></td>';
        echo '<td>' $today['impressions'] . '</td>';
        echo '<td>' $today['clicks'] . '</td>';
        echo '<td>' $today['ctr'] . '</td>';
        echo '<td>' $today['ecpm'] . '</td>';
        echo '<td>' arrondi_mnt_taux($today['total'], $today['clicks']) . 
' $US</td>';
        echo '<td>' $today['total'] . ' $US</td>';
        echo '<td>' arrondi_mnt_taux($today['total'], $taux) . 
' &euro;</td></tr>';
        echo '<tr><td><strong><a href="' htmlspecialchars(ADSENSE_LASTMONTH) .
 '">Mois dernier</a></strong></td>';
        echo '<td>' $lastmonth['impressions'] . '</td>';
        echo '<td>' $lastmonth['clicks'] . '</td>';
        echo '<td>' $lastmonth['ctr'] . '</td>';
        echo '<td>' $lastmonth['ecpm'] . '</td>';
        echo '<td>' arrondi_mnt_taux($lastmonth['total'], $lastmonth['clicks']
) . ' $US</td>';
        echo '<td>' $lastmonth['total'] . ' $US</td>';
        echo '<td>' arrondi_mnt_taux($lastmonth['total'], $taux) . 
' &euro;</td></tr>';
        echo '</table>';
    } else {
        $yesterday $adsense->yesterday();
        $today $adsense->today();
        $lastmonth $adsense->lastmonth();
        $thismonth $adsense->thismonth();
        if (date('G') < 9) {
            $jours_hier $day 2;  
//nombre de jours du mois jusqu'a avant hier
        } else {
            $jours_hier $day 1;  //nombre de jours du mois jusqu'a hier
        }
        $moyenne_imp round(($thismonth['impressions'] - $today['impressions'])
 / $jours_hier, );
        $moyenne_clic round(($thismonth['clicks'] - $today['clicks']) / 
$jours_hier, );
        $moyenne_ctr round(($thismonth['clicks'] - $today['clicks']) / 
                                        ($thismonth['impressions'] - $today[
'impressions']) * 1002);
        $moyenne_ecpm round(($thismonth['total'] - $today['total']) / 
                                           ($thismonth['impressions'] - $today[
'impressions']) * 10002);
        $moyenne_mnt round(($thismonth['total'] - $today['total']) / 
$jours_hier2);
        $jours_mois date('t');  //nombre de jours du mois
        $prev_imp round(($thismonth['impressions'] - $today['impressions']) / 
$jours_hier $jours_mois, );
        $prev_clic round(($thismonth['clicks'] - $today['clicks']) / 
$jours_hier $jours_mois, );
        $prev_ctr $moyenne_ctr;
        $prev_ecpm $moyenne_ecpm;
        $prev_mnt round(($thismonth['total'] - $today['total']) / $jours_hier 
$jours_mois2);
        echo '<table border="1">';
        echo '<tr><td></td><td><strong>Impressions</strong></td>';
        echo '<td><strong>Clics</strong></td>';
        echo '<td><strong>CTR</strong></td>';
        echo '<td><strong>eCPM</strong></td>';
        echo '<td><strong>CPC</strong></td>';
        echo '<td colspan="2"><strong>Montant total</strong></td></tr>';
        echo '<tr><td><strong>Moyenne / jour</strong></td>';
        echo '<td>' $moyenne_imp '</td>';
        echo '<td>' $moyenne_clic '</td>';
        echo '<td>' $moyenne_ctr '%</td>';
        echo '<td>' $moyenne_ecpm ' $US</td>';
        echo '<td>' arrondi_mnt_taux($moyenne_mnt$moyenne_clic) . 
' $US</td>';
        echo '<td>' $moyenne_mnt ' $US</td>';
        echo '<td>' arrondi_mnt_taux($moyenne_mnt$taux) . 
' &euro;</td></tr>';
        echo '<tr><td><strong><a href="' htmlspecialchars(ADSENSE_YESTERDAY) .
 '">Hier</a></strong></td>';
        echo '<td>' $yesterday['impressions'] . '</td>';
        echo '<td>' $yesterday['clicks'] . '</td>';
        echo '<td>' $yesterday['ctr'] . '</td>';
        echo '<td>' $yesterday['ecpm'] . '</td>';
        echo '<td>' arrondi_mnt_taux($yesterday['total'], $yesterday['clicks']
) . ' $US</td>';
        echo '<td>' $yesterday['total'] . ' $US</td>';
        echo '<td>' arrondi_mnt_taux($yesterday['total'], $taux) . 
' &euro;</td></tr>';
        echo '<tr><td><strong><a href="' htmlspecialchars(ADSENSE_TODAY) . 
'">Aujourd\'hui</a></strong></td>';
        echo '<td>' $today['impressions'] . '</td>';
        echo '<td>' $today['clicks'] . '</td>';
        echo '<td>' $today['ctr'] . '</td>';
        echo '<td>' $today['ecpm'] . '</td>';
        echo '<td>' arrondi_mnt_taux($today['total'], $today['clicks']) . 
' $US</td>';
        echo '<td>' $today['total'] . ' $US</td>';
        echo '<td>' arrondi_mnt_taux($today['total'], $taux) . 
' &euro;</td></tr>';
        echo '<tr><td><strong><a href="' htmlspecialchars(ADSENSE_LASTMONTH) .
 '">Mois dernier</a></strong></td>';
        echo '<td>' $lastmonth['impressions'] . '</td>';
        echo '<td>' $lastmonth['clicks'] . '</td>';
        echo '<td>' $lastmonth['ctr'] . '</td>';
        echo '<td>' $lastmonth['ecpm'] . '</td>';
        echo '<td>' arrondi_mnt_taux($lastmonth['total'], $lastmonth['clicks']
) . ' $US</td>';
        echo '<td>' $lastmonth['total'] . ' $US</td>';
        echo '<td>' arrondi_mnt_taux($lastmonth['total'], $taux) . 
' &euro;</td></tr>';
        echo '<tr><td><strong><a href="' htmlspecialchars(ADSENSE_THISMONTH) .
 '">Mois courant</a></strong></td>';
        echo '<td>' $thismonth['impressions'] . '</td>';
        echo '<td>' $thismonth['clicks'] . '</td>';
        echo '<td>' $thismonth['ctr'] . '</td>';
        echo '<td>' $thismonth['ecpm'] . '</td>';
        echo '<td>' arrondi_mnt_taux($thismonth['total'], $thismonth['clicks']
) . ' $US</td>';
        echo '<td>' $thismonth['total'] . ' $US</td>';
        echo '<td>' arrondi_mnt_taux($thismonth['total'], $taux) . 
' &euro;</td></tr>';
        echo '<tr><td><strong>Prévisionnel</strong></td>';
        echo '<td>' $prev_imp '</td>';
        echo '<td>' $prev_clic '</td>';
        echo '<td>' $prev_ctr '%</td>';
        echo '<td>' $prev_ecpm ' $US</td>';
        echo '<td>' arrondi_mnt_taux($prev_mnt$prev_clic) . ' $US</td>';
        echo '<td>' $prev_mnt ' $US</td>';
        echo '<td>' arrondi_mnt_taux($prev_mnt$taux) . ' &euro;</td></tr>';
        echo '</table>';
    }
} else {
    die('Could not login to AdSense account.');
}
?>
</body>
</html>
Fonctions du code source

Fonctions php / mysql PHP

  • define : Définit une constante - (PHP 4, PHP 5)
  • round : -
  • curl_init : Initialise une session cURL - (PHP 4 >= 4.0.2, PHP 5)
  • array : Crée un tableau - (PHP 4, PHP 5)
  • register_shutdown_function : Enregistre une fonction pour exécution à l'extinction - (PHP 4, PHP 5)
  • preg_match_all : Expression rationnelle globale - (PHP 4, PHP 5)
  • urlencode : Encode une chaîne en URL - (PHP 4, PHP 5)
  • join : Alias de implode() - (PHP 4, PHP 5)
  • preg_match : Expression rationnelle standard - (PHP 4, PHP 5)
  • str_replace : Remplace toutes les occurrences dans une chaîne - (PHP 4, PHP 5)
  • curl_setopt : Définit une option de transmission cURL - (PHP 4 >= 4.0.2, PHP 5)
  • die : Alias de la fonction exit() - (PHP 4, PHP 5)
  • nl2br : Insère un retour à la ligne HTML à chaque nouvelle ligne - (PHP 4, PHP 5)
  • htmlspecialchars : Convertit les caractères spéciaux en entités HTML - (PHP 4, PHP 5)
  • htmlspecialchars_decode : - (PHP 5 >= 5.1.0)
  • preg_quote : Protection des caractères spéciaux des expressions rationnelles - (PHP 4, PHP 5)
  • echo : Affiche une chaîne de caractères - (PHP 4, PHP 5)
  • preg_replace : Rechercher et remplacer par expression rationnelle standard - (PHP 4, PHP 5)
  • curl_errno : Retourne le dernier message d'erreur cURL - (PHP 4 >= 4.0.3, PHP 5)
  • curl_error : Retourne une chaîne contenant le dernier message d'erreur cURL - (PHP 4 >= 4.0.3, PHP 5)
  • curl_exec : Exécute une session cURL - (PHP 4 >= 4.0.2, PHP 5)
  • curl_getinfo : Lit les informations détaillant un transfert cURL - (PHP 4 >= 4.0.4, PHP 5)
  • curl_close : Ferme une session CURL - (PHP 4 >= 4.0.2, PHP 5)
  • file : Lit le fichier et renvoie le résultat dans un tableau - (PHP 4, PHP 5)
  • ereg : Expression rationnelle standard - (PHP 4, PHP 5)
  • date : Formate une date/heure locale - (PHP 4, PHP 5)

Commentaires (11)
Nouveau message KOogar
le 23 Juil 2008 à 02:41:00
Super, c'est un code officiel de GG ?

ps: il manquait les antislashs (\) pour les mots "aujourd'hui", je les est rajouté.
echo '<tr><td><strong>Aujourd\'hui</strong></td>';
Nouveau message forty
le 23 Juil 2008 à 11:28:00
Ce script est basé sur celui disponible ici: http://www.webtoolkit.info/php-adsense-account-monitor.html qui a nécessité des modifications pour marcher.
Pour les antislashes (\) c'est surement un stripslashes de trop dans ton code car j'ai copié collé un code que j'ai testé wink
Nouveau message forty
le 24 Juil 2008 à 09:33:00
Depuis ce matin ce code ne marche plus suite à une modification de google. Il faut remplacer le code :


Code:
"/<meta http-equiv=\"refresh\" content=\"0; url='(.*)'\">/si"

par :


Code:
"/<meta http-equiv=\"refresh\" content=\"0; url=&#39;(.*)&#39;\">/si"
Nouveau message Olravet
le 24 Juil 2008 à 11:52:00
Ben, ce sont les deux même !!!
Je suis aussi enquiquiné avec plein d'antislash en trop ou en pas assez, et la fonction "convert_url" est appellée mais n'est pas dans le code.
Nouveau message forty
le 24 Juil 2008 à 13:27:00
Bien vu : j'ai supprimé l'appel de la fonction "convert_url" qui ne sert a rien ici.

La version qui marche est disponible ici (en attendant de résoudre les problèmes d'affichage) : http://www.toplien.fr/get_adsense.txt
Nouveau message Olravet
le 24 Juil 2008 à 14:12:00
C'est mieux, mais j'ai pas php 5, alors j'ai du bêner "htmlspecialchars_decode" et toutes les infos "Private" devant function.


Et là, malgré tout ça ne veut pas se connecter.
Si t'as l'info, merci.
Nouveau message forty
le 24 Juil 2008 à 14:34:00
j'ai mis en ligne une nouvelle version de get_adsense.txt qui doit mieux marcher pour toi.

n'oublie pas de renseigner l'email et le mot de passe adsense.

Nouveau message Olravet
le 30 Juil 2008 à 08:25:00
Ca y est, ca marche, je te remercie...
Nouveau message Olravet
le 04 Aout 2008 à 15:37:00
Je me suis permis d'ajouter ça, en bas (juste après le dernier </table>)




Code:

$mamoyparjour = ($thismonth['total'] - $today['total'] )/ $jours_hier;
$restejrs = (100-$lastpay['total'])/$mamoyparjour;
$datefin = date("d-m-Y", mktime()+($restejrs*86400));
echo "<BR>Estimation fin du cycle le : ". $datefin."<BR>";
$mpay =date("n", mktime()+($restejrs*86400))+1;
if( date("j", mktime()+($restejrs*86400))>24){$mpay = $mpay+1;}
$moistext = array("","Janvier","Février","Mars","Avril",
"Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre");
echo "<i>( Paiement envoyé à la fin ".$moistext[$mpay]. ")</I>";




Ce qui permet d'avoir l'info de l'arrivée du prochain chèque !!!
Nouveau message forty
le 19 Déc 2008 à 09:36:00
il faut remplacer "/adsense/gaialogout" par "/adsense/signout" pour que ca marche
Nouveau message forty
le 28 Déc 2008 à 19:45:00
pour convertir en euro, il est possible de récupérer le taux euro/dollars avec ce code :


Code:
<?php
// code venant de : http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html#dev
$XMLContentfile("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
//the file is updated daily between 14:15 and 15:00 CET
$taux 1;
foreach (
$XMLContent as $line) {
    if (
ereg("currency='([[:alpha:]]+)'"$line$currencyCode)) {
        if (
ereg("rate='([[:graph:]]+)'"$line$rate)) {
            if (
$currencyCode[1] == 'USD') {
                
$taux $rate[1];
            }
        }
    }
}
?>


Pour afficher le montant en EUR, il suffit de remplacer les montants en $US par :


Code:
<?php
$montant_eur round($montant_usd $taux2);
?>

Poster un commentaire

:P :)
:wink: :lol:
:surprised: :confused:
:idea: :no:
Taille du texte:
Couleur:
 
Code de sécurité
Offres d'emploi
Librairie

Langages de programmation

La librairie est ouverte à tous et elle est accès principalement sur les langages PHP et MySQL. Vous trouverez aussi d'autres langages de programmation tel que le CSS, HTML, AJAX, ASP.. Plus de 300 références facilement accessibles. Visiter

  • MySQL 5.0
  • MySQL 5 : Guide de l'administrateur et du développeur
  • PHP - MySQL - AJAX - Coffret de 2 livres : Créez des applications professionnelles
  • PHP et MYSQL - MySQLi - PDO - Construisez votre application
  • Le grand livre de PHP 5 : Développemnt objet Applications pratiques
  • HTML 4
  • PHP et MySQL + (1Cédérom)
  • HTML
  • Programmer pour Internet : Notions fondamentales et mise en pratique (tcp/ip, http, html, java, php, MySQL, XML...)
  • PHP 5 & MySQL 5 : Formation complète technique