byrne86 Posted October 29, 2010 Share Posted October 29, 2010 I have a site, and there is an image with a link to another page, how can I make it so this is the only way to get to that page is by clicking on that image, and not by typing www.mywebsite.com/page.php into the address bar in a browser? Link to comment https://forums.phpfreaks.com/topic/217160-make-a-link-the-only-way-to-access-a-certain-page/ Share on other sites More sharing options...
revraz Posted October 29, 2010 Share Posted October 29, 2010 Can set a session and check it, or check the referrer. Link to comment https://forums.phpfreaks.com/topic/217160-make-a-link-the-only-way-to-access-a-certain-page/#findComment-1127951 Share on other sites More sharing options...
sharal Posted October 29, 2010 Share Posted October 29, 2010 You can try something like this, there might be some minor parse errors, it's just a rough sketch. Site with the image on: top page php script session_start(); if(isset($_POST['submitted'])) { $redirectPage = 'http://yourside.com/pageAccessedByClickingImage.php'; $_SESSION['access'] = 1; echo '<meta http-equiv="refresh" content="0;url='.$redirectPage.'" />'; } the image link: <form id="myform" action="" method="post"> <img src="someImage" onclick="document.getElementById("myform").submit()" /> <input type="hidden" name="submitted" value="1" /> </form> The page only accessible by clicking the image, top page php code: session_start(); if(!isset($_SESSION['access']) || $_SESSION['access'] != 1) { exit('You cannot access this page directly'); } The page only accessible by clicking the image, bottom page php code: $_SESSION['access'] = NULL; unset($_SESSION['access']; Link to comment https://forums.phpfreaks.com/topic/217160-make-a-link-the-only-way-to-access-a-certain-page/#findComment-1127952 Share on other sites More sharing options...
byrne86 Posted October 29, 2010 Author Share Posted October 29, 2010 I've put all that code into my site as suggested, I can no longer access the page directly, but the image is no longer a link to the page, I have changed the code and put in the name of the image etc etc, but it didn't work. I already have a session on the page with the image on it for logging in, I have put the session for the image link underneath that, will the 2 sessions conflict with each other? Or can there be 2 sessions running simultaneously? Thanks for the help, the code is mostly working, I'm guessing it's a small error on mypart as to why it isn;t fully working Link to comment https://forums.phpfreaks.com/topic/217160-make-a-link-the-only-way-to-access-a-certain-page/#findComment-1127969 Share on other sites More sharing options...
revraz Posted October 29, 2010 Share Posted October 29, 2010 Post your original code. This is why it's best to learn how to do it and not copy/paste someone else's code into yours. Link to comment https://forums.phpfreaks.com/topic/217160-make-a-link-the-only-way-to-access-a-certain-page/#findComment-1127978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.