duanhongxian6982 2015-10-07 18:58
浏览 24

阻止用户下载

I have website, and all users can download any file in download page. Just users who have accounts in my website can download; visitor cannot see the download page until login or registering on my website. I want now to do some changes; I want just download any file from a download page for active users who have more than 10 topics, any user who is less 10 topics cannot download any files. How can I do that?

Downloads

<?php 
if(!$allcategories)
{
    echo 'There are no downloads available!';
    return;
}

foreach($allcategories as $category)
{
?>
<p><h2><strong><?php echo $category->name?></strong></h2></p>
<ul>

<?php   
    # This loops through every download available in the category
    $alldownloads = DownloadData::GetDownloads($category->id);

    if(!$alldownloads)
    {
        echo 'There are no downloads under this category';
        $alldownloads = array();
    }

    foreach($alldownloads as $download)
    {
?>
    <li>
        <a href="<?php echo url('/downloads/dl/'.$download->id);?>">
            <?php echo $download->name?></a><br />
          <?php echo $download->description?><br />
          <em>Downloaded <?php echo $download->hits?> times</em></li>
<?php
    }
?><br />
</ul>
    <?php
}
?>

That is my download code .

  • 写回答

1条回答 默认 最新

  • douhan8581 2015-10-07 21:21
    关注

    This is a broad question with no information with the framework or db you are using. I'll assume you are using MySQL. I'll also assume you have a table called users with id | name | email | etc I'll also assume you have another table called topics with: id | userid | title | desc | etc Ok, I'll also assume that when a user logs in to your site, you are setting a session called $_SESSION["userid"];

    Now on the download page, run a query at the beginning (make sure you are connected to db before the following):

    $userid = $_SESSION["userid"];
    $result = mysql_query("SELECT count(*) from `topics` where `userid` = '$userid') or die(mysql_error());
    $topicCount = mysql_result($result,0);
    if($topicCount < 10){
    echo "You have $topicCount topics so far. You need a minimum of 10 to get access to downloads.";
    }
    

    You can change that message to anything you want so the users know why they don't have access to downloads.

    Good Luck

    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程