2012-12-16 193 views
-2

可能重複:
Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in PHP會話管理

你好我想在PHP設計一個網頁來實現類似的登錄會話和概念,並logout.Below是我的基本碼。

<?php  
session_start();  
$host = "localhost";  
$username = "USERNAME";  
$password = "PASSWORD";  
$db = "test";  
@mysql_connect($host,$username,$password) or die ("error");  
@mysql_select_db($db) or die("error");  
?> 

我上線3,請幫助得到一個錯誤的unexpected_T_CONSTANT_ENCAPSED_STRING刪除此error.Is它什麼毛病SOL注入?

+0

看這個問題:http://stackoverflow.com/questions/2719350/syntax-error-unexpected-t-constant-encapsed-string-in-php – kpotehin

+2

有你嘗試過使用框架?你不應該寫你自己的登錄代碼;安全風險太大 –

+1

您還應該使用'mysqli'函數而不是舊的不推薦使用的'mysql'。 – Cyclonecode

回答

0

首先,您應該停止使用MYSQL擴展名,因爲它很快就會被棄用。相反,你應該尋找其他豐富和安全的替代品,如MySQLiPDO_MySQL

檢查mysql_real_escape_string

如上頁面發現:

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be 

使用。另請參閱MySQL:爲更多 信息選擇API指南和相關常見問題解答。替代該功能包括:

mysqli_real_escape_string() 
    PDO::quote()