美好的一天!在PHP中製作評論部分的安全方式
今天我正在爲我的網站發表評論部分。我知道它不太難做出工作評論部分,但我想使它安全並防止SQL注入。
你有什麼建議,我應該怎麼做,我應該注意什麼?
我會在這裏發表我的想法,以便您可以告訴我哪部分是不安全的。
假設您需要註冊並登錄才能發表評論。
<html>
<head>
require 'connect.inc.php';
require 'function.php';
</head>
<body>
<?php
if(loggedin()){
$id = $_SESSION['user_id']; //loggedin function check if user is logged in
if(isset($_POST['comment_button'])){
$comment = $_POST['comment'];
mysql_query("INSERT INTO comments VALUES('','$id','$comment')");
}
?>
<form>
Comment:<br>
<textarea name='comment'></textarea>
<input type="submit" name="comment_button" value="Login"/>
</form>
<?php
}else{header('location: index.php');
} ?>
</body>
</html>
這是一些基本的想法,請注意在所有這一切,所以不要說新手上午驚訝,如果你看到不好的東西在這上面的代碼。感謝您的幫助。在這個here