PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 December 5th, 2012, 12:47 AM
anoopkumarreddy anoopkumarreddy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 anoopkumarreddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 31 sec
Reputation Power: 0
PHP5 - Giving access permissions for content for users

I would like to give the users the permissions to access the files from my e-commerce site to just have a preview.If he is having the preview of one file,he should not have the access to other files for some time until the preview time of first one which he is using is expired.Can anyone please help me out in developing this code.

Reply With Quote
  #2  
Old December 5th, 2012, 01:25 AM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,682 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 24 m 24 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
You'll have to explain a lot more and show some code before you can get any particularly useful advice.

Reply With Quote
  #3  
Old December 5th, 2012, 02:15 AM
anoopkumarreddy anoopkumarreddy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 anoopkumarreddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 31 sec
Reputation Power: 0
My actual requirement is I need to give permission to the registered users on my website to have a view of an eBook available from total number of books available.if user requests to view a book, he is allowed to view only that book and the view option for other books for the same user should be disabled for a week even though he completed reading the first one.

I have the code to limit the number of downloads but could not make it to change it to limit the number of views.
PHP Code:
<?php    include('includes/application_top.php');    if (!tep_session_is_registered('customer_id')) die;  // Check download.php was called with proper GET parameters   if ((isset($HTTP_GET_VARS['order']) && !is_numeric($HTTP_GET_VARS['order'])) || (isset($HTTP_GET_VARS['id']) && !is_numeric($HTTP_GET_VARS['id'])) ) {     die;   }    // Check that order_id, customer_id and filename match   $downloads_query = tep_db_query("select date_format(o.date_purchased, '%Y-%m-%d') as date_purchased_day, opd.download_maxdays, opd.download_count, opd.download_maxdays, opd.orders_products_filename from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " opd, " . TABLE_ORDERS_STATUS . " os where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = '" . (int)$HTTP_GET_VARS['order'] . "' and o.orders_id = op.orders_id and op.orders_products_id = opd.orders_products_id and opd.orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "' and opd.orders_products_filename != '' and o.orders_status = os.orders_status_id and os.downloads_flag = '1' and os.language_id = '" . (int)$languages_id . "'");   if (!tep_db_num_rows($downloads_query)) die;   $downloads = tep_db_fetch_array($downloads_query); // MySQL 3.22 does not have INTERVAL   list($dt_year, $dt_month, $dt_day) = explode('-', $downloads['date_purchased_day']);   $download_timestamp = mktime(23, 59, 59, $dt_month, $dt_day + $downloads['download_maxdays'], $dt_year);  // Die if time expired (maxdays = 0 means no time limit)   if (($downloads['download_maxdays'] != 0) && ($download_timestamp <= time())) die; // Die if remaining count is <=0   if ($downloads['download_count'] <= 0) die; // Die if file is not there   if (!file_exists(DIR_FS_DOWNLOAD . $downloads['orders_products_filename'])) die;    // Now decrement counter   tep_db_query("update " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " set download_count = download_count-1 where orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "'");  // Returns a random name, 16 to 20 characters long // There are more than 10^28 combinations // The directory is "hidden", i.e. starts with '.' function tep_random_name() {   $letters = 'abcdefghijklmnopqrstuvwxyz';   $dirname = '.';   $length = floor(tep_rand(16,20));   for ($i = 1; $i <= $length; $i++) {    $q = floor(tep_rand(1,26));    $dirname .= $letters[$q];   }   return $dirname; }  // Unlinks all subdirectories and files in $dir // Works only on one subdir level, will not recurse function tep_unlink_temp_dir($dir) {   $h1 = opendir($dir);   while ($subdir = readdir($h1)) { // Ignore non directories     if (!is_dir($dir . $subdir)) continue; // Ignore . and .. and CVS     if ($subdir == '.' || $subdir == '..' || $subdir == 'CVS') continue; // Loop and unlink files in subdirectory     $h2 = opendir($dir . $subdir);     while ($file = readdir($h2)) {       if ($file == '.' || $file == '..') continue;       @unlink($dir . $subdir . '/' . $file);     }     closedir($h2);      @rmdir($dir . $subdir);   }   closedir($h1); }   // Now send the file with header() magic   header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");   header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");   header("Cache-Control: no-cache, must-revalidate");   header("Pragma: no-cache");   header("Content-Type: Application/octet-stream");   header("Content-disposition: attachment; filename=" . $downloads['orders_products_filename']);    if (DOWNLOAD_BY_REDIRECT == 'true') { // This will work only on Unix/Linux hosts     tep_unlink_temp_dir(DIR_FS_DOWNLOAD_PUBLIC);     $tempdir = tep_random_name();     umask(0000);     mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777);     symlink(DIR_FS_DOWNLOAD . $downloads['orders_products_filename'], DIR_FS_DOWNLOAD_PUBLIC . $tempdir . '/' . $downloads['orders_products_filename']);     if (file_exists(DIR_FS_DOWNLOAD_PUBLIC . $tempdir . '/' . $downloads['orders_products_filename'])) {       tep_redirect(tep_href_link(DIR_WS_DOWNLOAD_PUBLIC . $tempdir . '/' . $downloads['orders_products_filename']));     }   }  // Fallback to readfile() delivery method. This will work on all systems, but will need considerable resources   readfile(DIR_FS_DOWNLOAD . $downloads['orders_products_filename']); ?>

Reply With Quote
  #4  
Old December 5th, 2012, 02:27 AM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,682 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 24 m 24 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Views and downloads are practically identical.

Before we can see your code you need to edit your post. If you haven't noticed all the newlines are gone - that's what happens when you paste your code into the popup dialog the PHP code tag gives you.
Leave the [php] tags in but re-paste your code in between them. Then Preview Post and make sure it's all readable.

Reply With Quote
  #5  
Old December 5th, 2012, 03:32 AM
anoopkumarreddy anoopkumarreddy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 anoopkumarreddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 31 sec
Reputation Power: 0
PHP Code:
<?php

  
include('includes/application_top.php');

  if (!
tep_session_is_registered('customer_id')) die;

// Check download.php was called with proper GET parameters
  
if ((isset($HTTP_GET_VARS['order']) && !is_numeric($HTTP_GET_VARS['order'])) || (isset($HTTP_GET_VARS['id']) && !is_numeric($HTTP_GET_VARS['id'])) ) {
    die;
  }
  
// Check that order_id, customer_id and filename match
  
$downloads_query tep_db_query("select date_format(o.date_purchased, '%Y-%m-%d') as date_purchased_day, opd.download_maxdays, opd.download_count, opd.download_maxdays, opd.orders_products_filename from " TABLE_ORDERS " o, " TABLE_ORDERS_PRODUCTS " op, " TABLE_ORDERS_PRODUCTS_DOWNLOAD " opd, " TABLE_ORDERS_STATUS " os where o.customers_id = '" . (int)$customer_id "' and o.orders_id = '" . (int)$HTTP_GET_VARS['order'] . "' and o.orders_id = op.orders_id and op.orders_products_id = opd.orders_products_id and opd.orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "' and opd.orders_products_filename != '' and o.orders_status = os.orders_status_id and os.downloads_flag = '1' and os.language_id = '" . (int)$languages_id "'");
  if (!
tep_db_num_rows($downloads_query)) die;
  
$downloads tep_db_fetch_array($downloads_query);
// MySQL 3.22 does not have INTERVAL
  
list($dt_year$dt_month$dt_day) = explode('-'$downloads['date_purchased_day']);
  
$download_timestamp mktime(235959$dt_month$dt_day $downloads['download_maxdays'], $dt_year);

// Die if time expired (maxdays = 0 means no time limit)
  
if (($downloads['download_maxdays'] != 0) && ($download_timestamp <= time())) die;
// Die if remaining count is <=0
  
if ($downloads['download_count'] <= 0) die;
// Die if file is not there
  
if (!file_exists(DIR_FS_DOWNLOAD $downloads['orders_products_filename'])) die;
  
// Now decrement counter
  
tep_db_query("update " TABLE_ORDERS_PRODUCTS_DOWNLOAD " set download_count = download_count-1 where orders_products_download_id = '" . (int)$HTTP_GET_VARS['id'] . "'");

// Returns a random name, 16 to 20 characters long
// There are more than 10^28 combinations
// The directory is "hidden", i.e. starts with '.'
function tep_random_name()
{
  
$letters 'abcdefghijklmnopqrstuvwxyz';
  
$dirname '.';
  
$length floor(tep_rand(16,20));
  for (
$i 1$i <= $length$i++) {
   
$q floor(tep_rand(1,26));
   
$dirname .= $letters[$q];
  }
  return 
$dirname;
}

// Unlinks all subdirectories and files in $dir
// Works only on one subdir level, will not recurse
function tep_unlink_temp_dir($dir)
{
  
$h1 opendir($dir);
  while (
$subdir readdir($h1)) {
// Ignore non directories
    
if (!is_dir($dir $subdir)) continue;
// Ignore . and .. and CVS
    
if ($subdir == '.' || $subdir == '..' || $subdir == 'CVS') continue;
// Loop and unlink files in subdirectory
    
$h2 opendir($dir $subdir);
    while (
$file readdir($h2)) {
      if (
$file == '.' || $file == '..') continue;
      @
unlink($dir $subdir '/' $file);
    }
    
closedir($h2); 
    @
rmdir($dir $subdir);
  }
  
closedir($h1);
}


// Now send the file with header() magic
  
header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
  
header("Last-Modified: " gmdate("D,d M Y H:i:s") . " GMT");
  
header("Cache-Control: no-cache, must-revalidate");
  
header("Pragma: no-cache");
  
header("Content-Type: Application/octet-stream");
  
header("Content-disposition: attachment; filename=" $downloads['orders_products_filename']);

  if (
DOWNLOAD_BY_REDIRECT == 'true') {
// This will work only on Unix/Linux hosts
    
tep_unlink_temp_dir(DIR_FS_DOWNLOAD_PUBLIC);
    
$tempdir tep_random_name();
    
umask(0000);
    
mkdir(DIR_FS_DOWNLOAD_PUBLIC $tempdir0777);
    
symlink(DIR_FS_DOWNLOAD $downloads['orders_products_filename'], DIR_FS_DOWNLOAD_PUBLIC $tempdir '/' $downloads['orders_products_filename']);
    if (
file_exists(DIR_FS_DOWNLOAD_PUBLIC $tempdir '/' $downloads['orders_products_filename'])) {
      
tep_redirect(tep_href_link(DIR_WS_DOWNLOAD_PUBLIC $tempdir '/' $downloads['orders_products_filename']));
    }
  }

// Fallback to readfile() delivery method. This will work on all systems, but will need considerable resources
  
readfile(DIR_FS_DOWNLOAD $downloads['orders_products_filename']);
?>

Last edited by E-Oreo : December 5th, 2012 at 11:24 PM.

Reply With Quote
  #6  
Old December 5th, 2012, 12:33 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,682 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 24 m 24 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Edit your post and keep the [php] tags.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Giving access permissions for content for users

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap