我的index.php中是否可以通過ajax直接發送一個php會話變量?
<?php
include_once '..\connect.php';
session_start();
if (isset($_SESSION['username'])){
$player_name = $_SESSION['username'];
} else {
header('Location: http://localhost/Inventory/index.php') ;
exit;
}
?>
和IM做出Ajax請求得到這request.php
<?php
//connect to databate and check for errors
$con = mysql_connect ("localhost","root","");
if (!$con) {
die ('Could not connect to database: ' . mysql_error());
}
//select database and check selection
if (!mysql_select_db ("GotA", $con)) {
die ('Could not select database: ' . mysql_error());
}
//I have to create this if not it doesnt find the sessions $player_name variable
$player_name = $_POST['name'];
//***Create Player Array**//
$player_info = "SELECT * from players where id = $player_name";
$player_info2 = mysql_query($player_info) or die ('Couldnt get players name');
$player_info3 = mysql_fetch_array($player_info2);
那麼它只是似乎不安全以檢索從使用可變發送的databe數據與JavaScript不是有沒有辦法從index.php(會話部分)直接使用變量? 還是安全的,只是通過使用JavaScript的信息?
請,請閱讀[這個問題](http://stackoverflow.com/questions/60174/best-way-to- stop-sql -injection-in-php)及其接受的答案。明白它。用它。 –
謝謝大家對您的意見和答案,我就要通過他們和鏈接時,我找到解決讀病報告 – Thaiscorpion