TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   opening a page only clicking a banner (http://www.talkphp.com/absolute-beginners/5530-opening-page-only-clicking-banner.html)

grigione 07-16-2010 06:25 PM

opening a page only clicking a banner
 
i need a script that permit of opening a page linked by banner clicking on banner
If users click on banner the page open, if user type url of page directly in browser don't open with phrase access denied or similar
i know that it's possible with $_SERVER['HTTP_REFERER'] but it can be easily spoofed
any alternative?

delayedinsanity 07-16-2010 08:16 PM

Stand over the guy with a stick, and swing it menacingly if they start typing anything in.

Krik 07-17-2010 01:35 AM

Create a unique id each time the banner is displayed. You store the id in a database with the time it was created. You then have the id appended to the url and if the time difference is greater than X amount the page they are going to denies them access.

This is bit like sessions ids but with a small twist.

grigione 07-17-2010 04:18 AM

Quote:

Originally Posted by Krik (Post 30849)
Create a unique id each time the banner is displayed. You store the id in a database with the time it was created. You then have the id appended to the url and if the time difference is greater than X amount the page they are going to denies them access.

This is bit like sessions ids but with a small twist.

great but i'ma newbie can you make an example of code ?
thanks

Krik 07-18-2010 02:39 AM

Writing up all the code and explaining it would be a very long post. I would suspect through explanation would be up around 10 printed pages. Just the code alone looks to be a minimum of 50 lines. And really just about every line would need a sentence or two to explain.

Now I have never had do what you need done but to do it I would go dig up code from several other projects and then use them together. And as all the various parts of the code, that I would use, I learned by research I thought the best idea would be to direct you to the information you need to do this. As this would let you learn things you may be able to use in future project.

First, I don't know if you know how to work with a databases so if you don't already you will need to know how to setup, access, and insert data into a database. As most hosts have MySQL I would recommend it for your database.

To setup a database your host will usually have tools that allow you to do this easily and may have a tutorial you could follow. To access data or insert data in a database you will find several tutorials online, as well php.net has all the php functions with examples and user comments (that have variations). Just look for all the function that are for working with a MySQL database.

Second, you will need be able to create a unique id. The code I have for this I learned when I was looking up how to generate passwords for people who forgot their password to an account.

That unique id will get stored in the database and passed to the next page in the url. You will want to use php.net to learn more about the $_GET super global for sending data in a URL and retrieving it.

Third, will also need to know how to work with a unix time stamp so again use php.net and check out the "time()" function.

Lastly you need to know how to send the user packing when there is no unique id or if it has expired and this is where you could use the $_SERVER['HTTP_REFERER'] combined with the "header" function, again look it up on php.net

Of course for each of these different areas you can do a google search and find other information as well.

I would only add that as you go along if run into a problem feel free to ask.

grigione 07-18-2010 03:36 PM

thanks for suggestion
However the procedure is really complicated for a newbie as me However searching in google i have found this script
http://www.devarticles.com/c/a/PHP/G...Ls-with-PHP/1/
Adapting this script instead of downloading a file i include my page to open
I'm trying and appear working
what do you think?

Krik 07-19-2010 05:01 AM

That is basically the same thing except they are storing the Unique id in a file, which is usually referred to as a "flat database".

Also there system doesn't have the unique url expire. The problem with this is the user will be able to reuse the url at any time so they could save it in their favorites or type in part of the url and the browser will suggest the rest.

You should note that the article was produced in 2003 and much of the PHP will be out of date. And I personally think it maybe over complicated.

Maybe you could try using a session. It is possible to store session data across pages fairly easily.

So you generate the unqiue id and then store it in a session.
PHP Code:

<?php
session_start
(); // this must be the very first line of code on all pages no exceptions

$alphanum '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            
$uniqueid '';
for (
$i 0$i 8$i++) {
    
$uniqueid .= $alphanum[(rand() % strlen($alphanum))];
}

$_SESSION['uniqueid'] = $uniqueid;
$_SESSION['time'] = time() + 21600//21600 adds 6 hours to the the current time
?>
<html>
<!-- your html here -->
<a href="http://www.yoursite.com/nextpage.php?id=<?php echo $uniqueid ?>"><img scr="yourbanner.jpg /></a>
</html>

Then on the page they are going to check the $_SESSION data against the url
PHP Code:

<?php
session_start
(); // this must be the very first line of code on all pages no exceptions

if (($_SESSION['uniqueid'] != $_GET['id']) || ($_SESSION['time'] <= time())) {
header('Location: $_SERVER['HTTP_REFERER']'// this line must be before any text or html is generated
}
else {
?>
<html>
<!-- Your HTML Here -->
</html>
<?php
}
?>


grigione 07-19-2010 09:36 AM

ok can you check the second part of code probabilly have you missing something i got a syntax error can you check?

Krik 07-19-2010 02:29 PM

PHP Code:

header("Location: $_SERVER['HTTP_REFERER']"

I am guessing that is it. Sorry about that just typed all right into the post. None of it was checked to see if it works.

If you keep getting the error or have other errors post the error message it helps some in figuring it out.

grigione 07-19-2010 02:40 PM

same error
however i have modified in this mode:
Quote:

header("Location: ".$_SERVER['HTTP_REFERER']);
and in this mode code is free error

i have tried your code but don't working
i have insert the second part of your code in a page named nextpage.php is correct?
i have tried have named first part of code submit.php and loading this page in browswer appear image con url and id that change at every reload but if i click the page reload but nothing of more


All times are GMT. The time now is 08:21 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0