Echo variable from another php file

I know how to refer variable from other page ?
variable in index.php ,result in main.php
how to solve this problem ? i took include , require statement but all statement listed out . Only get one variable , such as username , i hope user can see his login name on other page .

Thanks!

Please add some code showing what youre trying to do

If you want to show the name of a logged in user across pages I suggest you just add the data needed to the global session array

refer “username” variable in another php file showed

[php]<?php require_once('Connections/connection.php'); ?>

<?php require_once('Connections/function.php'); ?> <?php if (!isset($_SESSION)) { session_start(); } $_SESSION['PrevPage'] = "index.php"; ?> <?php //*******************************// // 登出 //*******************************// // index.php?logout=true $logout = $_SERVER['PHP_SELF'] . "?logout=true"; // index.php網址後面有logout參數 if ((isset($_GET['logout'])) &&($_GET['logout']=="true")) { $_SESSION['Username'] = NULL; $_SESSION['UserGroup'] = NULL; $_SESSION['PrevUrl'] = NULL; unset($_SESSION['Username']); unset($_SESSION['UserGroup']); unset($_SESSION['PrevUrl']); header("Location: index.php"); } ?> <?php //*******************************// //*******************************// $_SESSION['login_form_title'] = "請先登入"; if (isset($_POST['username']) && isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['password']; mysql_select_db('starofhk_ch26', $connection) or die('資料庫ch26不存在'); $query = sprintf("SELECT username, password, userlevel FROM member WHERE username=%s AND password=%s", GetSQLValue($username, "text"), GetSQLValue($password, "text")); $result = mysql_query($query, $connection) or die(mysql_error()); if ($result) { $totalRows = mysql_num_rows($result); if ($totalRows) { $_SESSION['Username'] = $username; $_SESSION['UserGroup'] = mysql_result($result, 0, 'userlevel'); header("Location: main.php"); } else { header("Location: login_form.php"); } } else { header("Location: login_form.php"); } } ?>
文學之星




帳號
密碼

<?php // 已經登入 if (isset($_SESSION['Username'])) { ?> 基本資料 》
登出 》
<?php } ?> 忘記密碼 》
[/php]

Please stop.

[php]<?php require_once('Connections/connection.php'); ?>

<?php require_once('Connections/function.php'); ?> <?php if (!isset($_SESSION)) { session_start(); }[/php] Absolutly ZERO point to go in and out of php like that. session_start() should be at the top of every page that will use anything in the session. It does not effect the session, it just makes the session stay active.

Your code is obsolete, insecure and has been completely removed from Php. You need to trash this code and start fresh with PDO.

https://phpdelusions.net/pdo

$_SERVER[‘PHP_SELF’] is vulnerable to an XSS attack. DO NOT use it.

Sponsor our Newsletter | Privacy Policy | Terms of Service