javascript - Disallowing PHP file to be accessed directly -


i have html form when gets submitted calls javascript function using ajax gets information php file using post , displays page.

the question is, possible make php file accessible when using above method instead of users being able access directly if go through js method , find it's location?

edit: adding bit more information people out. ajax calling external php file in order update contents of website based on php file returns. since ajax calls made in javascript can find out location , arguments function using , call php file directly, i'm trying avoid.

using php sessions bit hard in case, since i'm using ajax can't destroy session once external php file done since if session never renews because i'm using ajax update content of website without refreshing it.

i agree limscoder.

here how use tokens on submitting forms.

1) initialize , save on server (when page loaded on client side)

$token = $_session['token'] = md5(uniqid(mt_rand(),true)); 

2) add form

<input type="hidden" name="token" value="<?php echo $token;?>" /> 

3) when submitted check token using

if(isset($_session['token'], $_post['token']) && $_session['token'] == $_post['token']) { //code goes here } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -