简体   繁体   中英

include and function not working

Hi I still cannot figure out why these codes are not working and they have not produced out any error though I have tested the small example and it worked.

Here are these codes: securedlogin.php

<?php
include_once '/../toggleFirePHP.php'; //ok
// Start here...................................................................
function connect($database)
{
$firephp->group("In securedlogin.php, debugging begins");
$firephp->info("Info: Building parameters before login and use database");

/*** mysql hostname ***/
$hostname = 'localhost';

/*** mysql username ***/
$username = 'root';

/*** mysql password ***/
$password = '';

/*** mysql database ***/

$firephp->log("Log: hostname=".$hostname.", username=".$username.", password=".$password.", database=".$database);

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
    echo 'Connected to '.$database.' database'."<br/>";
    $firephp->warn("Warn: Login and connected to $database database is successful!");
    }
catch(PDOException $e)
    {
    $shorterr = $e->getMessage();
    $alertmsg = $shorterr;
    include 'alertmessage.php'; 
    echo $shorterr."<br/>";
    $firephp->error("Error: Login and connected to database is NOT successful! See below:");
    $firephp->error("Error: $shorterr");
    }

$firephp->groupEnd();
}
?>

toggleFirePHP.php

<?php
require_once($_SERVER['Document_ROOT'].'/firephp_include.php');
$firephp->setEnabled(TRUE);
?>

main.php

<?php
include_once '/toggleFirePHP.php'; //ok

// Start here...................................................................
include_once 'secured/securedlogin.php';

$firephp->group("In main.php, debugging begins");
$database = 'testdata1970_05';
$firephp->log("Log: Include securedlogin.php once and use $database");
connect($database);

$firephp->groupEnd();
?>

So what went wrong with these codes? Your help would be fully appreciated. Clement

If / first, you include file from root FS

Use

include_once './../toggleFirePHP.php';

and

include_once 'toggleFirePHP.php'; //ok

See the link and link

  • Correct one in securedlogin.php is '/toggleFirePHP.php'.
  • Correct one in toggleFirePhp.php is 'firephp_include.php'.
  • Correct one in main.php is 'toggleFirePHP.php' and '/secured/securedlogin.php'

The file system for root looks like below:-

Root folder
    toggleFirePHP.php
    main.php
    alertmessage.php
    firephp_include.php
    secured folder
         securedlogin.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM