Javascript is a client-side language, so scripts can be read and copied.
Now consider this example.
<html>
<head>
<title>title</title>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
$('#user').blur(function () {
var dataString = 'user=' + user;
$.ajax({
type: "POST",
url: "insertUser.php",
data: dataString
}
}
}
</script>
<label for='user' >User:</label>
<input id="user" type="text" />
</body>
insertUser.php :
<?php
$user = filter_input(INPUT_POST, 'user');
if (isset($user)) {
require_once("class.Database.php");
$db = Database::getInstance();
$mysqli = $db->getConnection();
$stmt = $mysqli->prepare("INSERT INTO Users (User) VALUES (?)");
$stmt->bind_param("s", $user);
$stmt->execute();
}
Could someone write a script in his localhost for inserting his own data using the path to insertUser.php? Anyway to solve this?