ronnie88 Posted July 24, 2008 Share Posted July 24, 2008 is there a php code that allows only one page to be referred to it? say I am at countdown.php and it is going to another page that update the mysql db and I don't want that page accessed by any other page... any help is appreciated Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/ Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 You can set a variable on the first page, and check it's there on the second. First page define(ALLOW_PAGE_LOAD, true); Second page if (!ALLOW_PAGE_LOAD) die ("You're not allowed to view this page directly"); Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598385 Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Author Share Posted July 24, 2008 thanks for the reply but I am having no luck... Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598389 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 whats it for exactly? I'm sure there is better alternatives. If its stop people going to the page when there not logged in. Then do a Session check. If its for admin only, Do a database authority level check... etc etc Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598418 Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 My understanding was that it's so people can't access the database query page directly, without going through another page first. in which case, the example i've given is the easiest method to use. My understanding is probably wrong though - it often is! Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598419 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 lol, well I'm thinking its probably something along the lines of a cron file, or some file that is only accessed at certain times. Which would make sense. In that case, the file should be put in the system root where it can't be touched. Or.... MD5 the file name, and MD5 the folder its in lol, and bolt it all up more secure then Alcatraz. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598426 Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 OMG - see, now I need to know what he actually wants. How am I gonna sleep tonight without knowing!!!!!! ;D Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598429 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 haha, I think you're gonna have to try and sleep, cause he doesn't appear to be online anymore lol. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598432 Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Author Share Posted July 24, 2008 Jonny is right its so they can't gain access to the mysql update :s but can't get that example you gave to work Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598441 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 so how do you access the page then? if no one can access it, then whats the point of having it ??? Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598443 Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Author Share Posted July 24, 2008 so users can't gain access by going to the php file to run a mysql command only when you refer by a certain page.. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598447 Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 What didn't work about my example?? Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598449 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 so users can't gain access by going to the php file to run a mysql command only when you refer by a certain page.. But are the users "logged in" to the website at the time. as in, they logged in using a form, and a session var has been set to show they are logged in. If thats the case, then its much easier to make a script to secure the mysql command file. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598451 Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Author Share Posted July 24, 2008 i probley did it wrong i placed this into the file that is going to the protected file <? define(ALLOW_PAGE_LOAD, true); ?> and this in the target file <? if (!ALLOW_PAGE_LOAD) die ("You're not allowed to view this page directly"); ?> lol I know it was an example but I don't know how I would incorporate it thanks yea logged in using a session and all Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598454 Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 It's the other way around. You define the variable in the first page, and check the variable in the page you want to protect. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598457 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 well if there logged in with a session. and if you got there info in a database. grab there ID or username, whatever from the database, and on the mysql script page, check if it equals the ID or username of who you want to have access to it. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598459 Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Author Share Posted July 24, 2008 well its actually a game start your own virtual airline and manage it... they wait however long there flight is then after the timer stops it gives a link to the php file which has the mysql update and adds the cash to there cash column... Thats what I meant johnny its in the right place.. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598463 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 ah I see... You can't let users refresh the page over and over again though.. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598467 Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Author Share Posted July 24, 2008 yup ??? Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598468 Share on other sites More sharing options...
unkwntech Posted July 24, 2008 Share Posted July 24, 2008 I'm not 100% sure how $_SERVER['HTTP_REFERER'] is handled on refresh (something I'm going to have to look at) but I would think you could just check this value. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598474 Share on other sites More sharing options...
samshel Posted July 24, 2008 Share Posted July 24, 2008 I agree with unkwntech, $_SERVER['HTTP_REFERER'] is the best method to use in this case. Refreshing doesnt loose the value of $_SERVER['HTTP_REFERER']. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598479 Share on other sites More sharing options...
unkwntech Posted July 24, 2008 Share Posted July 24, 2008 From some testing I just did I would remit my last post and advise against using $_SERVER['HTTP_REFERER']. I would do this on the page that does the query: <?php session_start() if(isset($_SESSION['varName'])) { die("You're not allowed to view this page directly"); } $_SESSION['varName'] = "123"; //do query ?> Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598483 Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Author Share Posted July 24, 2008 thank you but what is the varname for what do i put in the 123...? Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598489 Share on other sites More sharing options...
unkwntech Posted July 24, 2008 Share Posted July 24, 2008 You could leave them as it or make them anything you want it realy doesn't matter. Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598491 Share on other sites More sharing options...
ronnie88 Posted July 24, 2008 Author Share Posted July 24, 2008 I copied and pasted it in a php but i get Parse error: syntax error, unexpected T_IF in /home/virtual/public_html/blue_sky/insert2h.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/116367-solved-come-from-one-page-only/#findComment-598492 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.