包含的 php 文件:
<?php
session_start();
$mysqli = new mysqli('[removed]', '[removed]', '[removed]', '[removed]') or mysqli_connect_error();
function m($str, $mysqli) { return "'".$mysqli->real_escape_string($str)."'"; }
function h($str, $mysqli) { echo $mysqli->htmlspecialchars($str); }
$user = $mysqli->real_escape_string($_SESSION['username']);
$user_query = "SELECT points FROM users WHERE username =" .m($user, $mysqli) ."";
$result = $mysqli->query($user_query);
$row = $result->fetch_assoc();
$points = $row['points'];
function checklogin(){
if(isset($_SESSION['username'])){
echo $user . " Points: " . $points;
}
}
?>
html相关部分将是
<? include ('config.php')
session_start();
checklogin(); ?>
注意:在函数外部调用时,这些变量可以正常工作。