Possible reason for the error is because referrer is not 'reg.php' but its 'http://www.domian.com/ref.php'.
Just a couple of suggestions:
Don't rely on the referrer.
1. The browser may not always send the referrer.
2. The referrer may be spoofed or be purposely set to send the wrong information.
This may lead to a genuine submission being redirected to the form filling page and the form may never be submitted successfully.
Instead use sessions. Set a session variable. Set a session variable on the page that contains the form. On the form processing page, check if that session variable is set and let the process proceed accordingly.
Its very easy to integrate sessions into your script.
At the top of your form page, simply add the below snippet. The rest of the code on the page should remain unchanged.
PHP Code:
<?php
session_start();
$_SESSION['allow_form_to_be_submitted']=1;
?>
Now add the below snippet to the form processing page. Even here, the rest of the content remains unchanged.
PHP Code:
<?php
session_start();
if($_SESSION['allow_form_to_be_submitted']==1)
{
//process the inputs of the form
}
else
{
//redirect the user to the form filling page.
}
?>
Again, remember to add them to the 'top' of the page. Adding them anywhere in between may result in an ugly error.