this is creating post file
<?php
include "./database_credentials.php"
session_start();
//using try statement in order to stop php from printing database credentials
try {
$db = mysqli_connect($host,$username,$password,$db_name)
} catch (Exception $e){
// to alert the client that website is down using json.parse
echo '{"error":0}';
exit();
}
if(isset($_POST['text']) && isset($_SESSION['username'])){
//escape strings to prevent sql injections
$username = mysqli_real_escape_string($db,$_SESSION['username']);
$text = mysqli_real_escape_string($db,$_POST['text']);
$query = "INSERT INTO `posts_table_name` (`username`,`posts`) VALUES ('$username','$post')";
mysqli_query($db,$query);
mysqli_close($db);
exit();
}
?>
I tried to check http Referer variable from server variables but it didn't work and saying : undefined array key 'HTTP_REFERER' in array [$_SERVER]