Forum Moderators: open

Message Too Old, No Replies

Disallowing access to a page if a variable isn't present

Is this possible?

         

sarkye

8:39 am on Nov 27, 2001 (gmt 0)

10+ Year Member



I just came up with a great idea but to make it work I need to pick your brains a bit... hope you don't mind

This is all hypothetical so far but here goes.

Completing a process on page 1 redirects visitor to page two, passing a variable.

That part's easy enough, *but*...

in order to prevent visitor from bookmarking page two I want to:

a) make page two expire if the variable has been used before so that the page cannot be displayed again (a nice custom 'page expired' page would be nice here - but not sure how to go about that either just yet)

b) make page two inaccessible if a variable isn't present at all or if the variable isn't a valid one - i.e. generated by page one.

I know I can specify a referring URL for page two but that's not going to cut it - is it?

Thanks in advance :)

tedster

4:55 pm on Nov 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm asking for help behind the scenes, sarkye. I'm not sure there's a good client-side answer -- probably needs server-side scripting IMO.

sugarkane

5:06 pm on Nov 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could do this with cookies: Page one generates a cookie, which page two checks for. If it finds it, it allows access and then deletes the cookie, which effectively means that page one has to be visited again before any access to page two.

gethan

5:13 pm on Nov 27, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[sugarkane - beat me to it ;) - slow typing day.]

I haven't done exactly this but heres an idea;

Using javascript -

Page one.
Set a cookie that expires end of session. (or not if you want)

Page two.
Check for the cookie - if not present redirect to somewhere.

Make javascript read the content from a page.content.js file so that turning javascript off dosen't get round it.

There are lots of other ways to get around this method, but it will stop most people.

Other caveats
- needs cookies and javascript or no content shown.
- the content txt file - you could stick some basic encoding in that the javascript decodes based on referrer url.

Now if this was server side there are a thousand ways to do this ;)

sarkye

3:19 am on Nov 28, 2001 (gmt 0)

10+ Year Member



Thank you these replies :)

I like sugarkane's idea (Thanks sugarkane and gethan) of using cookies to the extent that it's quick and simple... but using cookies is something I'd rather avoid.

I did wonder if there was a server-side solution and I think I'd like to go that route so if you have any suggestions of the best method I'd appreciate it.

I'd have no problems (I don't think) with setting up either a cgi or PHP application.

Any suggestions?

gethan

10:21 am on Nov 28, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Basically - in php.
[perl]
<?php
if ($submit) {
print "Your page 2 contents";
} else {
print "Your page 1 contents +
<form action='$PHP_SELF' method='POST'>
<input type='submit' value='Page 2 Contents' name='submit'>
</form>";
}
?>
[/perl]

(Brett's pretty perl printer works nice on php too ;) )

sarkye

12:07 pm on Dec 2, 2001 (gmt 0)

10+ Year Member



I can't believe how well these few lines work gethan.

- and I tried really hard to get it to *not* work too!

Thank you :)

sarkye

12:13 pm on Dec 12, 2001 (gmt 0)

10+ Year Member



Thought I'd post the final outcome of my problem here just in case someone finds it useful...

I was looking for a way to prevent someone from revisiting a page from which a paid-for product is obtained by completing a form and receiving it attached to an autoresponder.

The help I got from everyone who replied was great (thank you everyone!), a few individual things worked but I didn't quite ever end up with what I was looking for when I put it all together.

Here's what I ended up doing when I started from scratch.

Visitor clicks through a sales link and pays with credit card

The 'get your widget here' page is written in PHP. The receipt number, which is passed from the 'give us your credit card number' page, is extracted from the URL using JavaScript and checked for matching entries in a mySQL database.

If no match is found where there IS a receipt number, all is well and the PHP page displays a very short form which when submitted, enters the new receipt number into the database and then sends email to the vendor who autoresponds with the purchased item.

If a receipt number is not found, PHP displays 'sorry, you have to purchase' section.

If a receipt number is found that matches one already in the database, PHP displays 'sorry, our records show that you've already received your widget'.

The only thing missing is that the PHP page can't tell if the receipt number is a VALID one if it's not present in the database... I may have to just risk it and see how it goes.

Hope that's of interest to someone :)