我有一些簡單的系統來上傳文件並使用數據庫爲每個特定用戶跟蹤它們。PHP變量聲明
我的問題是,我連接到checklogin.php
文件中的數據庫,該文件負責處理來自main_login.php
的$_POST
。
在文件 'checklogin.php':
$current_user_name = NULL;
這是所有文件的全局變量。現在,在文件signup.php
,我嘗試包括checklogin.php
定義變量:
require_once '/checklogin.php';
...
mysql_query("INSERT INTO " . tbl_name . " (username, userpassword, userisadmin)
VALUES (''" . $_POST['myusername'] . "',"
. "'" . md5($_POST['mypassword']). "',"
. "0)");
$current_user_name = $_POST['myusername'];
header("location:login_success.php");
正如你所看到的,我嘗試設置變量$current_user_name = $_POST['myusername'];
的價值,但是當header
轉到文件login_success.php
,它也有require_once '/checklogin.php';
,變量再次設置爲null
。
我該如何解決這個問題?即我如何存儲當前用戶以使其可以被所有文件訪問?
爲什麼不把'$ current_user_name'作爲'SESSION'變量呢? –
@ShankarDamodaran我仍然是php中的一個開始...... – user1234524521
在創建查詢之前,請始終從$ _POST或$ _GET中對輸入進行清理。 http://stackoverflow.com/questions/129677/whats-the-best-method-for-sanitizing-user-input-with-php – EdCapetti