Jump to content

Make a link the only way to access a certain page


byrne86

Recommended Posts

 

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'];

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.