The Little Guy Posted September 13, 2008 Share Posted September 13, 2008 I have a PHP file that is being called from other peoples web sites, is it possible for the file to only be accessed one time per page request? Quote Link to comment Share on other sites More sharing options...
DjMikeS Posted September 13, 2008 Share Posted September 13, 2008 I take it you don't have access to those other sites so you could do something with cookies ? Or perhaps a $_SESSION variable? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 14, 2008 Author Share Posted September 14, 2008 You are correct, no access at all. Im not sure how I would do cookies, or sessions with this, any idea? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 14, 2008 Share Posted September 14, 2008 I'm going to have to say that it's not possible. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 14, 2008 Author Share Posted September 14, 2008 They call the PHP file from a javascript file that I have, I could put some javascript in that couldn't I? Some thing like when the JS is called set a var to one, and if the var is already set to one don't let the php be included again. Also could I do a require_once, or include_once in the PHP file? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 14, 2008 Share Posted September 14, 2008 1) They can change Javascript... 2) Not really. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 14, 2008 Author Share Posted September 14, 2008 not everyone knows how to change JS, so it would give some protection. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 14, 2008 Author Share Posted September 14, 2008 The JS way does work, now is there any way for if someone knows how to edit JS? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 14, 2008 Share Posted September 14, 2008 The JS way does work, now is there any way for if someone knows how to edit JS? No, and it doesn't take a very smart person in order to edit plain text (which is what Javascript is). =/ Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 14, 2008 Author Share Posted September 14, 2008 Not sure if it matters, but the javascript is in a file on my server not theirs. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 14, 2008 Share Posted September 14, 2008 Ah. Can I see the contents of it so I know what it's doing? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 14, 2008 Author Share Posted September 14, 2008 I give them this code (past onto their server): <script type="text/javascript"> var idNum = '1'; var projectID = '6'; var projectCode = 'eb7sv7vnwc' </script><script type="text/javascript" src="http://superstats.phpsnips.com/javascripts/stats.js"></script> If they edit it if they they want, but then then they wont be able to see their website's stats. The code that it access looks like this (on my server): // JavaScript Document var width=screen.width; var height=screen.height; var ref=document.referrer; var loca=document.location; var to_str = 'location='+loca+'&width='+width+'&height='+height+'&ref='+ref+'&owner_id='+idNum+'&project_id='+projectID+'&projectCode='+projectCode; if(!called){ document.writeln('<script language="JavaScript" src="http://superstats.phpsnips.com/javascripts/jsProcess.php?'+to_str+'"></script>'); } var called = true; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 14, 2008 Share Posted September 14, 2008 Why does it matter how many times they call it? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 14, 2008 Author Share Posted September 14, 2008 cause if they place it on their site 50 times, and can modify my JS on the server, then for every person that loads the page, it will add 50 of the exact same thing to the database, it will also give inaccurate stats. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 14, 2008 Author Share Posted September 14, 2008 I just set it up to run the JavaScript file through a PHP file, and now that works... Wondering, if I can use PHP to check and see if the Javascript file was requested via URL or by another script, such as the other users Web site.... Quote Link to comment Share on other sites More sharing options...
kratsg Posted September 14, 2008 Share Posted September 14, 2008 The best thing I thought you could do is automatically run AJAX to post parameters to a PHP page about the details of the referrer, etc.. and update the database that way. Since they use javascript to access YOUR javascript, anything you want to do must be written up in your javascript. Hence, by using AJAX, you can: 1) update their information on how they've accessed your site 2) check to see if they've accessed too many times, etc... Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 14, 2008 Author Share Posted September 14, 2008 I was actually able to write a .htaccess file, that take the request and runs it though a PHP file, that way I can check things using PHP.... Here is what I have so far... header("Content-type: application/x-javascript"); if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){ //if($_SERVER['HTTP_REFERER'] == 'http://superstats.phpsnips.com/javascripts/stats.js'){ echo 'No Access!'; }else{ readfile('stats.js'); } //print_r($_SERVER); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.