IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

$GLOBALS : php4 à php5


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Étudiant
    Inscrit en
    Décembre 2007
    Messages
    630
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2007
    Messages : 630
    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.

  2. #2
    Membre chevronné
    Avatar de hornetbzz
    Homme Profil pro
    Directeur commercial
    Inscrit en
    Octobre 2009
    Messages
    482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France

    Informations professionnelles :
    Activité : Directeur commercial

    Informations forums :
    Inscription : Octobre 2009
    Messages : 482
    Par défaut
    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.

  3. #3
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    $GLOBALS existe dans toutes les versions de PHP.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  4. #4
    Membre éclairé
    Profil pro
    Étudiant
    Inscrit en
    Décembre 2007
    Messages
    630
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2007
    Messages : 630
    Par défaut
    Si ce n'est pas GLOBALS qui me pose problème, ca serait quoi alors ?
    Voici les codes concernés :

    reload.php :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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]);
        }
    }
    ?>

  5. #5
    Expert confirmé

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Par défaut
    quelle est ton niveau d'erreur sur PHP (display_errors et error_reporting) ?

  6. #6
    Membre émérite
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    625
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 625
    Par défaut
    Hello,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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.

  7. #7
    Membre éclairé
    Profil pro
    Étudiant
    Inscrit en
    Décembre 2007
    Messages
    630
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2007
    Messages : 630
    Par défaut
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 ...

  8. #8
    Membre éclairé
    Profil pro
    Étudiant
    Inscrit en
    Décembre 2007
    Messages
    630
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2007
    Messages : 630
    Par défaut
    Citation Envoyé par Petibidon Voir le message
    Hello,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Wamp] Migration PHP4 -> PHP5 : Ne reconnait plus les fonctions de bases!
    Par Thomus38 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 12
    Dernier message: 26/06/2006, 17h09
  2. Debian Apache2 php4 php5
    Par Jean_Benoit dans le forum Apache
    Réponses: 3
    Dernier message: 06/05/2006, 15h05
  3. Migration php4 > php5
    Par pierre50 dans le forum Langage
    Réponses: 3
    Dernier message: 23/04/2006, 14h53
  4. Réponses: 9
    Dernier message: 16/03/2006, 18h05
  5. migation php4 =>php5
    Par jeff_! dans le forum Zend
    Réponses: 6
    Dernier message: 27/02/2006, 22h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo