TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-02-2009, 03:48 AM   #1 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default Random links

I am having a problem, I am trying to setup a random id generator with php and mysql. I want it so that when people purchase the product it gives them a download link but I do not want them to have the link for ever. I want the link to last like 30 minutes. So what I want to do is make it do is when the product is purchased it last 30 minutes but then it cancels out and it gives the file a new ID. Can anyone help me? I am lost so far. Here is what I got so far.

PHP Code:
<?php

  $id 
$_GET['id'];

  
$links = array(

    
"download" => "http://www.domains.com/path/to/file.zip"

    
);

 

  
header("Location:".$links[$id]);

  exit;

?>
KingOfTheSouth is offline  
Reply With Quote
Old 09-02-2009, 04:43 AM   #2 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

I would create a unique id using php's unique id function and save this in the database with a time stamp.

When the user clicks on the link check the unique id in the database - that it exists & and that it has not expired yet.
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 09-02-2009, 04:57 AM   #3 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default

I do not really know how to do the unique ID to be honest this is my firs time doing anything like this and do not even know how to even set it up
KingOfTheSouth is offline  
Reply With Quote
Old 09-02-2009, 06:13 AM   #4 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

Its not hard at all...http://us3.php.net/manual/en/function.uniqid.php
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 09-02-2009, 07:12 AM   #5 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

Perhaps when an order comes, you can generate a random id by using something like this:

PHP Code:
$id md5(time());
$sql "INSERT INTO access (`down_id`,`down_created`) VALUES ('{$id}',".time().")"
Or more complicated if you like, then at the download side:

PHP Code:
// Check of expired download links
$expire time() - 30 60 60// Links created 30 minutes ago are expired
$sql "DELETE FROM access WHERE down_created < {$expired}";
mysql_query($sql);
// Now process the download
$id $_GET['id'];
$id mysql_real_escape_string($id);
$sql "SELECT * FROM access WHERE down_id='{$id}'";
$rs mysql_query($sql);
if (
mysql_num_rows != 1) {
    die(
'Unauthorized access!');
} else {
    
// Allow download of file

It's best you also rather use echo $file; than redirect to the link of the file in case some of your customers leak them.
TheOnly92 is offline  
Reply With Quote
Old 09-02-2009, 03:19 PM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

You could always try XKCD's method
__________________

Village Idiot is offline  
Reply With Quote
Old 09-02-2009, 03:31 PM   #7 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
You could always try XKCD's method
Hahah, gotta love XKCD, one of my favorites:
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 09-02-2009, 06:10 PM   #8 (permalink)
The Acquainted
 
KingOfTheSouth's Avatar
 
Join Date: Oct 2008
Location: Cincinnati
Posts: 151
Thanks: 14
KingOfTheSouth is on a distinguished road
Default

Quote:
// Check of expired download links
$expire = time() - 30 * 60 * 60; // Links created 30 minutes ago are expired
$sql = "DELETE FROM access WHERE down_created < {$expired}";
mysql_query($sql);
// Now process the download
$id = $_GET['id'];
$id = mysql_real_escape_string($id);
$sql = "SELECT * FROM access WHERE down_id='{$id}'";
$rs = mysql_query($sql);
if (mysql_num_rows != 1) {
die('Unauthorized access!');
} else {
// Allow download of file
}
I understand that more than any of the others my problem is actually knowing how to set it up correctly on a page and working.
KingOfTheSouth is offline  
Reply With Quote
Old 09-03-2009, 08:42 AM   #9 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

So what's not working now?
TheOnly92 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unique random number? code_junkie Advanced PHP Programming 4 12-21-2008 12:01 AM
Showing random links with an array paulOr Advanced PHP Programming 6 10-24-2008 09:28 AM
Eyes Random String Generator EyeDentify Script Giveaway 10 06-11-2008 05:11 PM
Random Items without a Database WinSrev Tips & Tricks 11 12-05-2007 02:50 AM
How Rdoanm is Rondam? Wildhoney General 3 09-19-2007 01:32 PM


All times are GMT. The time now is 03:03 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design