Q:

How to protect my php code from auto executing when loading the page

I want to protect my action page so that whenever user or hacker directly hits www.something.com/process.php That should not have any effect .Please help me securing the process.php page when user directly hits from browser address bar .
I have following code in index.html
<form method="post" action="process.php">
    Name:<input type="text" name="txtname"><br/>
    Age :<input type="text" name="age"><br/>
    <input type="submit" value="submit">
</form>

I have following in process.php
<?php
//connection code to connect and use database...

$name=mysql_real_escape_string($_POST['txtname']);
$age=mysql_real_escape_string($_POST['age']);

$sql="insert into table values('$name','$age')";
$result=mysql_query($sql);

?>

A:

Add the following line to the top of process.php
if (empty($_POST)) {
    header('HTTP/1.0 403 Forbidden');
    die('Restricted');
}

