redarrow Posted March 9, 2008 Share Posted March 9, 2008 Advance thank you... I need a way that users can download a file when the payment is accepted from paypal...... But in saying that the user will be sent to the web site page stright afther paying from ebay....... Do i use ipn from pay pal.... Do i use a code that let the file download automaticly from only useing there ip once.... Do i let the user enter a code pre made and cheek there ip aginst database... Do i let the user enter a code pre made and cheek there pay pal info from ipn aginst database... What would you do... Open to sugestions........... oh ye admin will be posting code afther sugestions thank you sorry to do it this way cheers....... Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 9, 2008 Share Posted March 9, 2008 Here's a starter for you - one-time URLs for downloads http://www.onlamp.com/pub/a/php/2002/12/05/one_time_URLs.html Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 9, 2008 Author Share Posted March 9, 2008 thank you but if the file is valid i need the file to download shall i add the force download code to it and thank you for the code..... what force download code will i need for a .txt file cheers.. /* If there was a valid token in $token, output the secret file: */ if( $valid ) { readfile($secretfile); } else { print "Invalid URL!"; } Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 9, 2008 Author Share Posted March 9, 2008 SOLVED thank you... <?php /* * get_file.php * * Script for validating a request through a secret token, passing a file * to the user, and ensuring the token can not be used again. * */ /* Retrive the given token: */ $token = $_GET['q']; if( strlen($token)<32 ) { die("Invalid token!"); } /* Define the secret file: */ $secretfile = "tmp/secret_file.txt"; /* This variable is used to determine if the token is valid or not: */ $valid = 0; /* Define what file holds the ids. */ $file = "tmp/urls.txt"; /* Read the whole token-file into the variable $lines: */ $lines = file($file); /* Truncate the token-file, and open it for writing: */ if( !($fd = fopen("tmp/urls.txt","w")) ) die("Could not open $file for writing!"); /* Aquire exclusive lock on $file. */ if( !(flock($fd,LOCK_EX)) ) die("Could not equire exclusive lock on $file!"); /* Loop through all tokens in the token-file: */ for( $i = 0; $lines[$i]; $i++ ) { /* Is the current token the same as the one defined in $token? */ if( $token == rtrim($lines[$i]) ) { $valid = 1; } /* The code below will only get executed if $token does NOT match the current token in the token file. The result of this will be that a valid token will not be written to the token file, and will therefore only be valid once. */ else { fwrite($fd,$lines[$i]); } } /* We're done writing to $file, so it's safe release the lock. */ if( !(flock($fd,LOCK_UN)) ) die("Could not release lock on $file!"); /* Save and close the token file: */ if( !(fclose($fd)) ) die("Could not close file pointer for $file!"); /* If there was a valid token in $token, output the secret file: */ if( $valid ) { header ("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header ("Content-Type: application/octet-stream"); header ("Content-Length: " . filesize($secretfile)); header ("Content-Disposition: attachment; filename=$secretfile"); readfile($secretfile); } else { print "Invalid URL!"; } ?> [/solved] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.