Limit user to clicking only one link on a page

Links for php scripts

Moderators: macek, egami, gesf

nato595
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Apr 12, 2012 9:48 am

Limit user to clicking only one link on a page

Postby nato595 » Thu Apr 12, 2012 9:50 am

I'm looking for how to create a web script that allows user to only click one link, or view one video when multiple are listed.
I want to make a webpage that has 5 different links or videos on it, but I want a user to only be able to click one, Then no others for that session.
Any ideas?
Thanks!

FishBird
New php-forum User
New php-forum User
Posts: 21
Joined: Thu Apr 12, 2012 8:05 am
Contact:

Re: Limit user to clicking only one link on a page

Postby FishBird » Thu Apr 12, 2012 10:23 am

A very simple solution will be a session check:

video1 5 minutes:

$_SESSION['wait'] = strtotime("+ 5 minutes");

check on video2:

if( @$_SESSION['wait'] > time() ) exit("You must wait ".($_SESSION['wait'] - time())." seconds");

nato595
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Apr 12, 2012 9:48 am

Re: Limit user to clicking only one link on a page

Postby nato595 » Thu Apr 12, 2012 11:02 am

I really like that you say there is a "simple solution"! Thanks for giving me hope!
I am unfortunately completely uneducated in the way of Sessions.
Would you be able to really help me out and give an example for the very basic page samples below.

Code: Select all

<html>
<body>
You can watch one video today.  Please choose only one:
<br><br><br>
Option 1:
<iframe width="560" height="315" src="http://www.youtube.com/embed/VAWjsVoDpm0" frameborder="0" allowfullscreen></iframe><br><br>
Option 2:
<iframe width="560" height="315" src="http://www.youtube.com/embed/jRGrNDV2mKc" frameborder="0" allowfullscreen></iframe><br><br>
Option 3:
<iframe width="560" height="315" src="http://www.youtube.com/embed/2s3iGpDqQpQ" frameborder="0" allowfullscreen></iframe><br><br>
Option 4:
<iframe width="560" height="315" src="http://www.youtube.com/embed/ujEph5vFwmc" frameborder="0" allowfullscreen></iframe><br><br>
</body>
</html>


Or using links instead of iframes:

Code: Select all

<html>
<body>
You can watch one video today.  Please choose only one:
<br><br><br>
Option 1:
<a href="location1.php">link 1</a><br><br>
Option 2:
<a href="location2.php">link 2</a><br><br>
Option 3:
<a href="location3.php">link 3</a><br><br>
Option 4:
<a href="location4.php">link 4</a><br><br>
</body>
</html>

FishBird
New php-forum User
New php-forum User
Posts: 21
Joined: Thu Apr 12, 2012 8:05 am
Contact:

Re: Limit user to clicking only one link on a page

Postby FishBird » Thu Apr 12, 2012 11:16 am

Why whould you want users to only be able to see only one youtube video?

I dont see any php code in your scripts, so what do you have?...

sessions wont work for a whole day, and you can easily delete your cookies and the limitation is gone.

You should store the ipaddress of the user in a sql table, or let them login. Check if they visited before this day, and if they have dont show the video.

I am not going to build a copy and paste script for you. With this information you can make it yourself, or hire someone to do it.

nato595
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Apr 12, 2012 9:48 am

Re: Limit user to clicking only one link on a page

Postby nato595 » Thu Apr 12, 2012 11:37 am

Even allowing them to only view one per hour would be fine. It doesn't have to be a calendar day.
The reason behind the idea is so we can offer short demo videos of our product, but only allow a "sneak peek" (meaning one) before they have to call and speak with a sales person to get more info.

I don't currently have an existing page, the code I posted above were just quick examples that I free handed on here for example purposes. I really don't care if the final product is PHP, HTML, JavaScript, etc.

Also, it really doesn't need to be 100% bypass proof. If a user wants to jump through the hoops of clearing their cache and/or cookies or using a different machine, it's not that big of a deal. We aren't dealing with private records or anything, if they want to see our demo videos that bad, that's okay with me!

No worries, if I don't get a direct solution on here I'll probably have to end up hiring somebody. I appreciate your hints though!

Thanks!

FishBird
New php-forum User
New php-forum User
Posts: 21
Joined: Thu Apr 12, 2012 8:05 am
Contact:

Re: Limit user to clicking only one link on a page

Postby FishBird » Thu Apr 12, 2012 11:45 am

Allright, here is a very simple solution. Only lasts while the session is active (usually untill the user closes the browser):

Code: Select all

<?php

session_start()

$viewed = isset( $_SESSION['viewed'] ) ? true : false;

if( $viewed ===true ){
?>

You have already watched today

<?php
exit;
}
$_SESSION['viewed'] = true;
?>
<html>
<body>
You can watch one video today.  Please choose only one:
<br><br><br>
Option 1:
<a href="location1.php">link 1</a><br><br>
Option 2:
<a href="location2.php">link 2</a><br><br>
Option 3:
<a href="location3.php">link 3</a><br><br>
Option 4:
<a href="location4.php">link 4</a><br><br>
</body>
</html>


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest