含まれている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(); ?>
注:変数は、関数の外部で呼び出されたときに完全に機能します。