全球php文件

Every php page starts with this:

<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name=""; // Table name

// Connect to server and select database.
$con = mysqli_connect($host,$username,$password,$db_name); 

session_start();
?>

So how can I make a .php file that save those variables and include them in the start of every html page. And if I want to use $con variable from it. how to use it.

I think better use require_once or include_once, because if you include one page to another with include 'config.php'; on top - you get a message

'A session had already been started - ignoring session_start()'

PHP documentation:

http://php.net/manual/en/function.require-once.php

http://php.net/manual/en/function.include-once.php

Put this code in a file (eg. config.php) and include/require it in all other php files

<?php
include 'config.php';

// here you could use the $con variable

PHP documentation:

http://php.net/manual/en/function.include.php

http://php.net/manual/en/function.require.php