Précédent   Forum des professionnels en informatique > PHP > Langage > Débuter
Débuter Forum d'entraide pour débuter en PHP. Avant de poster -> Cours PHP, FAQ PHP, Outils PHP, etc.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 22/11/2010, 16h47   #1
Membre habitué
 
Étudiant
Inscription : décembre 2007
Messages : 543
Détails du profil
Informations personnelles :
Âge : 26

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2007
Messages : 543
Points : 130
Points : 130
Envoyer un message via MSN à ikuzar
Par défaut $GLOBALS : php4 à php5

Bonjour,
je suis débutant en développement Web. Mon stage consiste à étudier une solution open source d'analyse de log. je bloque sur la partie Web...
la partie Web est écrit en php4 ( le produit date de 2006 ... ) et moi j'ai apache2 avec php5.

-- Mon problème : mon code php ne trouve pas mon fichier de config contenant l'adresse IP du serveur à contacter. Du coup il est impossible de se connecter au serveur. Je pense que c'est à cause de la variable $GLOBALS["conf"]. Apparement elle n'est pas reconnue par PHP5 alors que cette variable stocke justement le chemin vers le fichier de config ... Si ce n'est pas cette variable qui est à l'origine du problème, est ce que il yl aurait d'autres variables susceptibles .. ?
PS : J'ai plein de $GLOBALS dans mes fichiers...

-- que dois-je faire ?

Merci d'avance pour votre aide.
ikuzar est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/11/2010, 17h37   #2
Membre chevronné
 
Avatar de hornetbzz
 
Homme
Directeur commercial
Inscription : octobre 2009
Messages : 474
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 44
Localisation : France

Informations professionnelles :
Activité : Directeur commercial

Informations forums :
Inscription : octobre 2009
Messages : 474
Points : 681
Points : 681
Envoyer un message via Skype™ à hornetbzz
bonjour,

Déjà tu peux t'imprégner de la documentation très fournie.

Par exemple, sur les variables globales.

Une remarque: c'est un peu... touchy mais tu peux faire cohabiter plusieurs versions de php sur une même machine.

bon courage.
hornetbzz est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/11/2010, 17h38   #3
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
$GLOBALS existe dans toutes les versions de PHP.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/11/2010, 17h50   #4
Membre habitué
 
Étudiant
Inscription : décembre 2007
Messages : 543
Détails du profil
Informations personnelles :
Âge : 26

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2007
Messages : 543
Points : 130
Points : 130
Envoyer un message via MSN à ikuzar
Si ce n'est pas GLOBALS qui me pose problème, ca serait quoi alors ?
Voici les codes concernés :

reload.php :
Code :
1
2
3
4
5
6
7
8
9
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
require_once ('classes/Session.inc');
Session::logcheck("MenuPolicy", "PolicyServers"); // Who manage server can reload server conf
require_once ("classes/Session.inc");
require_once ("classes/Security.inc");
$what = GET('what');
$back = GET('back');
ossim_valid($what, OSS_ALPHA, OSS_NULLABLE, 'illegal:' . _("What"));
ossim_valid($back, OSS_ALPHA, OSS_PUNC, 'illegal:' . _("back"));
if (ossim_error()) {
    die(ossim_error());
}
/* what to reload... */
if (empty($what)) $what = 'all';
require_once ('ossim_conf.inc');
$ossim_conf = $GLOBALS["CONF"];
/* get the port and IP address of the server */
$address = '127.0.0.1';
$port = '40001';
$address = $ossim_conf->get_conf("server_address");
$port = $ossim_conf->get_conf("server_port");
/* create socket */
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
    printf(gettext("socket_create() failed: reason: %s\n") , socket_strerror($socket));
}
/* connect */

$result = socket_connect($socket, $address, $port);
echo "<b> socket_connect() reussie : \$result = $result</b>";//Aro
if ($result < 0) {
    printf(gettext("socket_connect() failed: reason: %s %s\n") , $result, socket_strerror($result));
}

$in = 'connect id="1" type="web"' . "\n";
$out = '';
socket_write($socket, $in, strlen($in));
$out = socket_read($socket, 2048);
//echo "<p/><b> \$out = $out </b>";// Aro
if (strncmp($out, 'ok id="1"', 9) != 0) {
    // If the server is down / unavailable, clear the need to reload
    // Switch off web indicator
    require_once ('classes/WebIndicator.inc');
    if ($what == "all") {
        WebIndicator::set_off("Reload_policies");
        WebIndicator::set_off("Reload_hosts");
        WebIndicator::set_off("Reload_nets");
        WebIndicator::set_off("Reload_sensors");
        WebIndicator::set_off("Reload_plugins");
        WebIndicator::set_off("Reload_directives");
        WebIndicator::set_off("Reload_servers");
    } else {
        WebIndicator::set_off("Reload_" . $what);
    }
    // Reset main indicator if no more policy reload need
    if (!WebIndicator::is_on("Reload_policies") && !WebIndicator::is_on("Reload_hosts") && !WebIndicator::is_on("Reload_nets") && !WebIndicator::is_on("Reload_sensors") && !WebIndicator::is_on("Reload_plugins") && !WebIndicator::is_on("Reload_directives") && !WebIndicator::is_on("Reload_servers")) {
        WebIndicator::set_off("ReloadPolicy");
    }
    // update indicators on top frame
    $OssimWebIndicator->update_display();
    echo gettext("Error connecting to server-----") . " ...\n";
    exit;
}
$in = 'reload-' . $what . ' id="2"' . "\n";
$out = '';
socket_write($socket, $in, strlen($in));
$out = socket_read($socket, 2048);
if (strncmp($out, 'ok id="2"', 9) != 0) {
    echo gettext("Bad response from server") . " ...\n";
    exit;
}
socket_close($socket);
// Switch off web indicator
require_once ('classes/WebIndicator.inc');
if ($what == "all") {
    WebIndicator::set_off("Reload_policies");
    WebIndicator::set_off("Reload_hosts");
    WebIndicator::set_off("Reload_nets");
    WebIndicator::set_off("Reload_sensors");
    WebIndicator::set_off("Reload_plugins");
    WebIndicator::set_off("Reload_directives");
    WebIndicator::set_off("Reload_servers");
} else {
    WebIndicator::set_off("Reload_" . $what);
}
// Reset main indicator if no more policy reload need
if (!WebIndicator::is_on("Reload_policies") && !WebIndicator::is_on("Reload_hosts") && !WebIndicator::is_on("Reload_nets") && !WebIndicator::is_on("Reload_sensors") && !WebIndicator::is_on("Reload_plugins") && !WebIndicator::is_on("Reload_directives") && !WebIndicator::is_on("Reload_servers")) {
    WebIndicator::set_off("ReloadPolicy");
}
// update indicators on top frame
$OssimWebIndicator->update_display();
?>

<html>
<head>
  <link rel="stylesheet" type="text/css" href="../style/style.css"/>
</head>
<body>
  <p> <?php
echo gettext("---------------------------Reload completed successfully----------------------------------------------"); ?> </p>
<?php
$location = urldecode($back);
sleep(2);
echo "<script>
///history.go(-1);
window.location='$location';
</script>
";
?>
</body>
</html>
ossim_conf.inc :

Code :
1
2
3
4
5
6
7
8
9
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
define('CONF_FILE', "/etc/ossim/framework/ossim.conf");
if (!isset($GLOBALS["CONF"])) $GLOBALS["CONF"] = new ossim_conf();
class ossim_conf {
    var $conf;
    var $db_conf;
    function ossim_conf($read_db = True) {
        $this->conf = ossim_conf::get_conf_from_file(CONF_FILE);
        if ($read_db) $this->db_conf = ossim_conf::get_conf_from_db();
    }
    function get_conf_from_file($conffile) {
        if (!$fd = fopen($conffile, "r")) {
            echo "Can't open config file ($conffile)\n<br/>";
            exit();
        }
        $configuration = NULL;
        while (!feof($fd)) {
            $line = fgets($fd, 2048);
            $line = trim($line);
            if (strncmp($line, "#", 1)) {
                $conf = explode('=', $line);
                $type = trim($conf[0]);
                if (isset($conf[1])) {
                    $value = trim($conf[1]);
                    $configuration["$type"] = $value;
                }
            }
        }
        fclose($fd);
        return $configuration;
    }
    function get_conf_from_db() {
        require_once ("classes/Config.inc");
        $configuration = new Config();
        return $configuration->get_list();
    }
    function get_conf($type, $debug = true) {
        if (isset($this->conf[$type])) return $this->conf[$type];
        elseif (isset($this->db_conf[$type])) return $this->db_conf[$type];
        /*
        * $debug == FALSE
        * don't start output, session cache limiter problem
        */
 
        if ($debug) {
            print "<b>Warning++++++++</b>: Error reading configuration: ";
            print "<b>$type</b> is not set<br/>\n";
        }
        return NULL;
    }
    function is_in_file($type) {
        return isset($this->conf[$type]);
    }
}
?>
ikuzar est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/11/2010, 17h53   #5
Modérateur
 
Inscription : septembre 2010
Messages : 7 058
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 058
Points : 8 401
Points : 8 401
quelle est ton niveau d'erreur sur PHP (display_errors et error_reporting) ?
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/11/2010, 18h12   #6
Membre chevronné
 
Inscription : mars 2005
Messages : 583
Détails du profil
Informations forums :
Inscription : mars 2005
Messages : 583
Points : 651
Points : 651
Hello,

Code :
define('CONF_FILE', "/etc/ossim/framework/ossim.conf");
A priori ceci est le chemin de ton fichier de config.
La question est donc probablement de la validité de ce chemin.
__________________
Pourfendeur de singletons en croisade
Petibidon est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/11/2010, 09h53   #7
Membre habitué
 
Étudiant
Inscription : décembre 2007
Messages : 543
Détails du profil
Informations personnelles :
Âge : 26

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2007
Messages : 543
Points : 130
Points : 130
Envoyer un message via MSN à ikuzar
Je ne sais pas c'est quoi mon niveau d'erreur sur php

Voici l'erreur que j'ai obtenu ( quand je clique sur le bouton "reaload" ):

Code :
1
2
3
4
5
6
7
8
9
10
 
Warning: Error reading configuration: server_address is not set
Warning: Error reading configuration: server_port is not set
 
Warning: socket_connect() [function.socket-connect]: Host lookup failed [-10001]: Unknown host in /opt/ossim/www/conf/reload.php on line 64
 
Warning: socket_write() [function.socket-write]: unable to write to socket [32]: Broken pipe in /opt/ossim/www/conf/reload.php on line 72
 
Warning: socket_read() [function.socket-read]: unable to read from socket [107]: Transport endpoint is not connected in /opt/ossim/www/conf/reload.php on line 73
Error connecting to server ...
ikuzar est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/11/2010, 12h29   #8
Membre habitué
 
Étudiant
Inscription : décembre 2007
Messages : 543
Détails du profil
Informations personnelles :
Âge : 26

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2007
Messages : 543
Points : 130
Points : 130
Envoyer un message via MSN à ikuzar
Citation:
Envoyé par Petibidon Voir le message
Hello,

Code :
define('CONF_FILE', "/etc/ossim/framework/ossim.conf");
A priori ceci est le chemin de ton fichier de config.
La question est donc probablement de la validité de ce chemin.
Ce chemin est bien valide. Je lui ai attribué un droit 777 temporairement mais ca ne marche toujours pas...

$GLOBAL["CONF_FILE"] n'est appelé nul part. alors qu'on définit : define('CONF_FILE', "/etc/ossim/framework/ossim.conf") ... serait-ce normal ?
j'ai essayé de remplacé $GLOBAL["CONF_FILE"] par $GLOBAL["CONF"] mais ca ne marche toujours pas...
ikuzar est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/11/2010, 13h32   #9
Membre chevronné
 
Inscription : mars 2005
Messages : 583
Détails du profil
Informations forums :
Inscription : mars 2005
Messages : 583
Points : 651
Points : 651
Salut,

define définit (<-pas mal !) une constante.

Elle est utilisée dans le constructeur de la classe.
Code :
$this->conf = ossim_conf::get_conf_from_file(CONF_FILE);
Les soucis peuvent être identifiés avec ceci :
Citation:
Warning: Error reading configuration: server_address is not set
Warning: Error reading configuration: server_port is not set
Ce sont des messages d'erreur personnalisés. Il semblerait que le fichier de conf de ton script ne contienne pas certaines informations. Difficile de t'en dire plus, c'est propre à ton script, ce n'est pas vraiment un problème de PHP.
__________________
Pourfendeur de singletons en croisade
Petibidon est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/11/2010, 14h35   #10
Membre éclairé
 
Inscription : octobre 2004
Messages : 235
Détails du profil
Informations forums :
Inscription : octobre 2004
Messages : 235
Points : 360
Points : 360
Que contient /etc/ossim/framework/ossim.conf ?
Est-ce qu'il y a une ligne :

Code :
1
2
 
server_address = xxxxxx
Et

Code :
1
2
 
server_port = xxxxx
??
Joker-eph est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/11/2010, 14h44   #11
Membre habitué
 
Étudiant
Inscription : décembre 2007
Messages : 543
Détails du profil
Informations personnelles :
Âge : 26

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2007
Messages : 543
Points : 130
Points : 130
Envoyer un message via MSN à ikuzar
oui, dans /etc/ossim/framework/ossim.conf, j'ai bien rempli les champs :
server_address = 127.0.0.1
server_port = 40001

Quand je les met en dur dans le code ca marche bien, mais je bloque au niveau du lecteur du fichier de conf ...
ikuzar est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/11/2010, 15h14   #12
Membre éclairé
 
Inscription : octobre 2004
Messages : 235
Détails du profil
Informations forums :
Inscription : octobre 2004
Messages : 235
Points : 360
Points : 360
Tu peux peut-être déboguer la fonction get_conf_from_file(), c'est la que le fichier est ouvert, les lignes sont lues, et les paramêtres sont définis.
Joker-eph est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/11/2010, 17h20   #13
Membre habitué
 
Étudiant
Inscription : décembre 2007
Messages : 543
Détails du profil
Informations personnelles :
Âge : 26

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : décembre 2007
Messages : 543
Points : 130
Points : 130
Envoyer un message via MSN à ikuzar
Le problème était au niveau du fichier de config : server_address était commenté ...
ikuzar est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h48.


 
 
 
 
Partenaires

Hébergement Web