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

 

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.