if(!empty($_REQUEST['user'])){ $user=$_REQUEST['user']; echo "welcome $user !";}<form name='msgform' action ='<?= $_SERVER['PHP_SELF'] ?>' method='post'> <input type='hidden' name='user' value='<?=$user?>'>這段的那個$_REQUEST['user']和 $_SERVER['PHP_SELF']是什么意思?
2 回答

慕仙森
TA貢獻1827條經驗 獲得超8個贊
一.$_REQUEST['user'] =$_GET[''user'']+$_POST['user']
$_GET[''user'']和$_POST['user']同時存在,則用$_POST['user']
建議不要使用,還是用$_GET,$_POST,
二.$_SERVER['PHP_SELF'] 獲取當前頁面的地址
http://aaa/php/ ---> /php/index.php
注意:<form name='msgform' action ='<?= $_SERVER['PHP_SELF'] ?>'>
如果一定要這樣寫的話,一定要對'msgform'進行過濾,
否則我瀏覽器里地址寫成: http://aaa/php/index.php/test/foo
就可以訪問/php/index.php/test/foo (就是加什么執行什么)
改成htmlentities($_SERVER['PHP_SELF']) 比較好
- 2 回答
- 0 關注
- 748 瀏覽
添加回答
舉報
0/150
提交
取消