Ideas anyone! Link or click validation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
torads
Forum Newbie
Posts: 8
Joined: Tue Sep 07, 2010 2:44 pm

Ideas anyone! Link or click validation

Post by torads »

Hello,

I have a free app that I want to distribute on my website but in exchange I would like the potential downloader to view 3 randomly generated webpages before they would get to the download link. All they need to do is view the pages and once validated they would get the link to the download.

So eg.

I would have 3 links to pages that would open in a new tab or window. once they have viewed that page when they come back they would need to click on link #2 and then 3.

I need to figure out some code that would validate that the link was clicked and then move on to the next.

Or ideas similar to what I need would be great as well.

thanks in advance
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Ideas anyone! Link or click validation

Post by oscardog »

The easiest way would be to set a SESSION or COOKIE each time a page is viewed. So at the top of each page have:

Code: Select all

$_SESSION['page1'] = "yes";
Then to check if they have all been visited:

Code: Select all

if(isset($_SESSION['page1']) && isset($_SESSION['page2']) && isset($_SESSION['page3']) {
//Output download link here
}
torads
Forum Newbie
Posts: 8
Joined: Tue Sep 07, 2010 2:44 pm

Re: Ideas anyone! Link or click validation

Post by torads »

I like the idea of using the session as opposed to the cookies as some users will have cookies turned off.

I know a bit of php but have not used sessions at all before.

I use the include alot to allow myself to change certain things without having to change them on each page.

I have done some reading about sessions but am still getting a parse error on the line that checks if they have all been visited.

Do you mind going into detail more about where the lines need to be placed and on what pages?

I have added this to the top of 3 pages that I will start with as the 3 links.

Page 1

<?php
session_name ('visitor');
ini_set("session.use_cookies',0); // Don't use cookies
session_start()
$_SESSION['page1'] = "yes";
?>


Page 2

<?php
session_name ('visitor');
ini_set("session.use_cookies',0); // Don't use cookies
session_start()
$_SESSION['page2'] = "yes";
?>


Page 3

<?php
session_name ('visitor');
ini_set("session.use_cookies',0); // Don't use cookies
session_start()
$_SESSION['page3'] = "yes";
?>


I added the line that checks to see if they have been visited to the main page where all 3 links are placed.

<?php
session_name ('visitor');
session_start();
if(isset($_SESSION['page1']) && isset($_SESSION['page2']) && isset($_SESSION['page3']) {
<a href="my file">Download</a>
}


Of course "my file" would be replaced with the download link.


the session_name and session_start was me trying to figure it out after getting the error.

It says parse error on line 4 which would be the if statement.

I am probably way off but a few more minutes of your time could push me in the right direction.

Thank again for your quick response.
torads
Forum Newbie
Posts: 8
Joined: Tue Sep 07, 2010 2:44 pm

Re: Ideas anyone! Link or click validation

Post by torads »

Ok I have fixed all of the errors. Some of you might have noticed in the previous post a few brackets missing and such.

I was also getting an error with the line.

$_SESSION['page3'] = "yes";

I changed to

$_SESSION['page3'] = 'yes';

and error went away.

But I'll move on to my current issue:

After clicking on all 3 links, The else statement still holds true for some reason. I am not sure why its not validating.

Code: Select all

<?php
if (isset($_SESSION['page1']) && isset($_SESSION['page2']) && isset($_SESSION['page3'])) {
echo'<a href="my file">Download</a>';
}
else
{
echo 'You have not looked at all 3 pages yet';
}
?>

Here's the code that is placed on the 3 pages I am linking to.

Code: Select all

<?php
session_name ('visitor');
ini_set('session.use_cookies',0);  // Don't use cookies
session_start();
$_SESSION['page3'] = 'yes';
?>
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Ideas anyone! Link or click validation

Post by Jonah Bron »

You need to refresh the page to update the session info. Have them click a reload link after they've view the other pages.
torads
Forum Newbie
Posts: 8
Joined: Tue Sep 07, 2010 2:44 pm

Re: Ideas anyone! Link or click validation

Post by torads »

Tried that without success.

I'm making an error somewhere else.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Ideas anyone! Link or click validation

Post by Jonah Bron »

What does the error say?
torads
Forum Newbie
Posts: 8
Joined: Tue Sep 07, 2010 2:44 pm

Re: Ideas anyone! Link or click validation

Post by torads »

Thats the thing, I'm not getting any more errors, It's just skipping the download link and still displays what happens in the else part of the statement.

After clicking on the 3 links I thought it would pass that validation and show the download link, or link to the download page.

Any ideas on what i should check?

I think there's possibly something wrong with my server logging the session.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Ideas anyone! Link or click validation

Post by Jonah Bron »

Change

Code: Select all

$_SESSION['page1'] = "yes";
In each page to

Code: Select all

$_SESSION['page_count'] += 1;
And change

Code: Select all

if(isset($_SESSION['page1']) && isset($_SESSION['page2']) && isset($_SESSION['page3']) {
To

Code: Select all

if(isset($_SESSION['page_count']) >= 3) {
torads
Forum Newbie
Posts: 8
Joined: Tue Sep 07, 2010 2:44 pm

Re: Ideas anyone! Link or click validation

Post by torads »

I made the changes and still the validation doesn't pass.

then I searched the web for some quick answers and decided to try changing the session_start() to the second line and its now working.

thanks to both of you for your assistance.

It is greatly appreciated
Post Reply