2012-12-16 191 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()