Jump to content

Getting image link to be the only way to access a page


byrne86

Recommended Posts

I have asked this before, but I didnt have any code to show, so here is what I have:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Main Page</title>
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-19675449-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script</head>>

<body>

<div id="top-bar">

<div class="bar-content"><a href="index.php">HOME</a> | <a href="howitworks.php">HOW IT WORKS</a> | <a href="advertisingopportunities.php">ADVERTISE HERE</a> | <a href="about.php">ABOUT US</a> | <a href="contactus.php">CONTACT US</a></div>
</div>
<?php include "system/buttonimage.php"; ?>
<div class="main">

<div class="topad">
  <div class="jackpot">
    <div class="addthis_toolbox addthis_32x32_style addthis_default_style">
      <table width="55" border="0">
        <tr>
          <td width="19"><a class="addthis_button_facebook"></a></td>
          <td width="26"><a class="addthis_button_twitter"></a></td>
          </tr>
        <tr>
          <td><a class="addthis_button_google"></a></td>
          <td><a class="addthis_button_compact"></a></td>
          </tr>
        </table>
      </div>
  </div>
    <div class="adbannertop"><a href="howitworks.php"><img src="images/mainbanner.gif" width="728" height="90" /></a></div>
    <div align="center"></div>
</div>
  <div class="buttondiv">
  
  <?php echo $buttonimage ?>
      
  <div class="leftad">
    <div align="left">
      <table width="247" border="0">
        <tr>
          <td width="120" height="161"> </td>
          <td width="117"> </td>
          </tr>
        </table>
      </div>
</div>
<div class="rightad">
      <div align="right">
        <table width="247" border="0">
          <tr>
            <td width="120" height="171"> </td>
            <td width="117"> </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</div>
<div align="center">
  <p>Copyright © 2010 TwistFire Ltd. All Rights Reserved</p>
  <p><a href="termsandconditions.php">Terms and Conditions</a> - <a href="privacypolicy.php">Privacy Policy</a></p>
  <p>    <!-- Begin W3Counter Tracking Code -->
<script type="text/javascript" src="http://www.w3counter.com/tracker.js"></script>
<script type="text/javascript">
w3counter(45635);
</script>
<noscript>
<div><a href="http://www.w3counter.com"><img src="http://www.w3counter.com/tracker.php?id=45635" style="border: 0" alt="W3Counter" /></a></div>
</noscript>
<!-- End W3Counter Tracking Code--></p>
</div>
</body>
<!--Copyright © 2010 TwistFire Ltd. All Rights Reserved-->
</html>

 

The above code is the main page and the line "echo $buttonimage" is the line used to get my image depending what it shud be, and the code used to get the image for $buttonimage is here:

 

<?php

include "ccn.php";
$sql1l = mysql_result(mysql_query('SELECT time FROM db1 WHERE id = 1'), 0);
$sql2 = mysql_result(mysql_query('SELECT minute FROM db1 WHERE id = 1'), 0);
$var1 = $sql2l+2;
$buttonoffpic = "<img src=\"images/buttonoff.png\" width=\"398\" height=\"398\" />";
$buttononpic = "<a href=\"entryform.php\"><img src=\"images/buttonon.png\" width=\"398\" height=\"398\" BORDER=0/></a>";

if ($sql1 == date(H))
$buttonimage = $buttononpic;
else
$buttonimage = $buttonoffpic;
//<!--Copyright © 2010 TwistFire Ltd. All Rights Reserved-->
?>

 

And here is the page that I want the access to be limited to via the link, and not allow people direct access, I have some session code that someone gave me, and that does work, its just getting the session to allow people on the pge when they click the image "buttonon.png".

 

<?php
session_start();
if(!isset($_SESSION['access']) || $_SESSION['access'] != 1) {
   exit('You cannot access this page directly');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Good Luck...</title>
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-19675449-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>

<body>
<div id="top-bar">

<div class="bar-content"><a href="index.php">HOME</a> | <a href="howitworks.php">HOW IT WORKS</a> | <a href="advertisingopportunities.php">ADVERTISE HERE</a> | <a href="about.php">ABOUT US</a> | <a href="contactus.php">CONTACT US</a></div>
</div>
<div class="main2" id="main2">
  <p> </p>
  <h2><img src="images/thanksforplaying.gif" width="500" height="200" /></h2>
  <form action="formverification.php" method="post">
    <p>Please fill in the form to register your entry</p>
	<div align="center">
	  <table width="389" border="0">
	    <tr>
	      <td width="235">First Name</td>
	      <td width="144"><input type="text" name="firstname" id="firstname" /></td>
        </tr>
	    <tr>
	      <td>Second Name</td>
	      <td><input type="text" name="surname" id="surname" /></td>
        </tr>
	    <tr>
	      <td>Email Address</td>
	      <td><input type="text" name="email" id="email" /></td>
        </tr>
	    <tr>
	      <td> </td>
	      <td><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /></td>
        </tr>
	    <tr>
	      <td>Security Code</td>
	      <td><input id="security_code" name="security_code" type="text" /></td>
        </tr>
      </table>
  </div>
	<div align="center"></div>
	<p>By clicking the button below, you are agreeing to the <a href="termsandconditions.php">terms and conditions</a> of this website</p>
	<p>
	  <input type="submit" name="submit" value="I have read and accept the terms and consitions of this website - Submit" />
    </p>
  </form>
</div>
<div align="center">
  <p>Copyright © 2010 TwistFire Ltd. All Rights Reserved </p>
  <p>    <!-- Begin W3Counter Tracking Code -->
<script type="text/javascript" src="http://www.w3counter.com/tracker.js"></script>
<script type="text/javascript">
w3counter(45635);
</script>
<noscript>
<div><a href="http://www.w3counter.com"><img src="http://www.w3counter.com/tracker.php?id=45635" style="border: 0" alt="W3Counter" /></a></div>
</noscript>
<!-- End W3Counter Tracking Code--></p>
</div>
</body>
<!--Copyright © 2010 TwistFire Ltd. All Rights Reserved-->
</html>
<?php
$_SESSION['access'] = NULL;
unset($_SESSION['access']);
?>

 

I need to be able to click the image and go to the page, but not be able to access t directly.

 

Thanks

 

C.Byrne

Link to comment
Share on other sites

the browser sends the click information to PHP. there is no way I can think of that PHP can be positive the user actually clicked the button. i guess you could add a Javascript onclick event to the image, so at least it's not a direct link. but the user could still look at the javascript and navigate to the page themselves. another alternative might be to have PHP look for the x/y coordinates submitted when a graphic link is clicked. but again, the user could just spoof these values. i don't think there is a (mostly) foolproof method for accomplishing this using just HTML and PHP. you might do better using a Flash button.

Link to comment
Share on other sites

I dont think its about clicking the image to get access, its just clicking the link on a specific page to grant access.

 

sessions is a good way to go.

although the example given by your friend is very simple

u have to set the session variable in yer main page, at the very top (before the html code)

<?php session_start(); $_SESSION['access']=1; ?>

 

will get it to work, but u should read up on sessions, especially the expiry period, and session_destroy.

Link to comment
Share on other sites

yes, if it's just about making sure you were on another page first, just set session value on the first page and check for it on the second page:

 

page1.php

session_start();
$_SESSION['page1'] = true;

 

page2.php

session_start();
if (!isset($_SESSION['page1']) || $_SESSION['page1'] !== true) {
     header("location: page1.php");
     exit();
}

Link to comment
Share on other sites

I know how to use a session to check the previous page, but I need the page in my link to never be accessed unless the user clicks the link, the link is not always on my site, so I dont want people just typing the name of the page in and accessing the form whenever they want.

 

I had code to set the session variable, but the user could just go to page1, then type the url of page2 because page1 had set the session variable.

 

Would something like this work...

 

<?php 
include "myphpfile1";
session_start();
if ($variable1(from myphpfile1) = x)
$_SESSION['access']=1;
?>

 

What this would do is check the same variable that makes the link appear on my page, and if that link has appeared then the session would be set... I cant really test this at the minute, because my site is live, and I cant really go messing about with it, and to set up all the stuff with this one link would be a pain, but if no one knows for sure whether this would work then I will test it.

 

Link to comment
Share on other sites

The link you're creating needs to have a code that changes with each click and needs matched against code in the destination page.

 

Try something like the following.

 

generateCode(){
  $possible = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $code = '';
  $i = 0;
  while ($i < 40) {
    $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
    $i++;
  }
  return $code;
}
If (is_set($_SESSION['access']) && is_set($_GET['accesscode'])){
  if($_SESSION['access'] == $_GET['accesscode']){
    //code to display the first page
  }else{
    //code to display the requested page
  }
}
//no  matter what page you're on, you'll need the following code
$accesscode=generateCode();
$_SESSION['access'] = $accesscode;
echo ('<a href="page.php?accesscode=' . $accesscode . '">Next page</a>';

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.