PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 30th, 2002, 08:31 AM
direwolf's Avatar
direwolf direwolf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Australia
Posts: 39 direwolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 30 sec
Reputation Power: 8
generate random link to url

I am after a bit of advice on how to write a script that will generate a link to a file that will only work once.

i.e. the script is called and it generates a link

http://mydomain.com/12345.....filename.zip

this link would only remain valid for either a set time or a one off click through.

The next time the script is called it would give a different url i.e.

http://mydomain.com/53762.....filename.zip

I'm not too sure where to start. Perhaps linking in to a mysql database?

Reply With Quote
  #2  
Old June 30th, 2002, 09:55 AM
csmall csmall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Pittsburgh, PA
Posts: 54 csmall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
If you are willing to use a link something like "http://mydomain.com/file.php?c=12345&n=filename.zip", then you could try something like this:

Create a table in mySQL with the fields 'code' (varchar(xx) where 'xx' is the length of your secret code), 'filename' (varchar(yy) where 'yy' is the maximum length of a file's name), and 'expires' (DATETIME).

In the file that gives the link to the user:
PHP Code:
 $sSecretCode = ... your 'random' number generating code ... ;
$sFileName = ... filename to be accessed ... ;
$iValidSecs = ... seconds that link should be valid ...

if (
mysql_query("INSERT INTO tblCodes SET code='$sSecretCode',
      filename='$sFileName',expires=(NOW() + $iValidSecs)"
)) {
  
// Code was added to database
  
$sLink "http://mydomain.com/file.php?c=$sSecretCode&n=$sFileName";
  echo 
"The link to the file is: <A HREF=\"$sLink\">$sLink</A>";
} else {
  
// Code was not added
  
echo "There was an error setting up your link.";
}

// Use this file access as a trigger to clean out tblCodes
$rslt mysql_query("DELETE FROM tblCodes WHERE expires<NOW()"); 


In the file 'file.php':
PHP Code:
// Use this file access as a trigger to clean out tblCodes
$rslt mysql_query("DELETE FROM tblCodes WHERE expires<NOW()");

$sSQL "SELECT * FROM tblCodes WHERE code='" addslashes($c)
         . 
"' AND filename='" addslashes($n) . "' AND expires>=NOW()";
if (
$rslt mysql_query($sSQL)) {
   if (
mysql_num_rows($rslt) > 0) {
      
// valid code for file

      // DELETE CODE (allow only one access of the file)
      
$rslt mysql_query("DELETE FROM tblCodes WHERE code='" addslashes($c)
            . 
"' AND filename='" addslashes($n) . "'");

      
// Take the user to the file:
      
header("Location:  http://mydomain.com/filedir/" addslashes($n));
   } else {
      echo 
"File is not accessible.";
   }
} else {
   echo 
"Error attempting to access file.";


Reply With Quote
  #3  
Old June 30th, 2002, 06:58 PM
direwolf's Avatar
direwolf direwolf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Australia
Posts: 39 direwolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 30 sec
Reputation Power: 8
hmmm looks good.

I will now go and have a play. Thanks

Reply With Quote
  #4  
Old October 7th, 2002, 03:04 AM
direwolf's Avatar
direwolf direwolf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Australia
Posts: 39 direwolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 30 sec
Reputation Power: 8
In the file.php code are the variables
PHP Code:
 $c

$n 

classed as globals?

If I turn register_globals off on my server will I have define these first?

i.e.
PHP Code:
// to work with php 4.0.6
$c $HTTP_GET_VARS["c"];
$n $HTTP_GET_VARS["n"]; 

Reply With Quote
  #5  
Old October 7th, 2002, 02:29 PM
csmall csmall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Pittsburgh, PA
Posts: 54 csmall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
In a word... Yes.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > generate random link to url


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT