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? Quote Link to comment 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. Quote Link to comment 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']; Quote Link to comment 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 Quote Link to comment 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. 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.