SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    User downloadable links in php

    Hi all,

    Am pretty much new to php. I hve a php site with user login, i hve maintained session. I hve pdf download in blog and articles page.

    I hve to show the pdf for all, but it should be downloadable only for registered users, for others when they click it i want to show a alert "Please sign in to Download".

    Please help me out in this issue.

    You can see the files here:
    http://212.227.137.184/tim_04-02-10/index.php

    user id: dhilipr

    pass: dhilipr

    i hve placed a downloadable pdf in Blog and Articles page. Now only the register user can see the pdf files. Bcoz i hve hide it initially and after logging in i hve revealed it.

    What i want is, i hve to show the pdf for all users, but only registered users can able to download it. for others it should show a alert like "sign in to download"

    Thanks & Regards,
    Dhilip. R

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    User downloadable links in php

    Hi all,

    Am pretty much new to php. I hve a php site with user login, i hve maintained session. I hve pdf download in blog and articles page.

    I hve to show the pdf for all, but it should be downloadable only for registered users, for others when they click it i want to show a alert "Please sign in to Download".

    Please help me out in this issue.

    You can see the files here:
    http://212.227.137.184/tim_04-02-10/index.php

    user id: dhilipr

    pass: dhilipr

    i hve placed a downloadable pdf in Blog and Articles page. Now only the register user can see the pdf files. Bcoz i hve hide it initially and after logging in i hve revealed it.

    What i want is, i hve to show the pdf for all users, but only registered users can able to download it. for others it should show a alert like "sign in to download"

    Thanks & Regards,
    Dhilip. R

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should have a php page which downloads the file and pass the downloading file to that file in query string. For example save the following script in download.php file. (I assume you save download.php file in the root).
    PHP Code:
    if($user_is_logged_in){
        
    $filetodownload addslashes($_GET['filename']);
        if(
    file_exists($filetodownload)){
            
    header('Content-type: application/pdf');
            
    header('Content-Disposition: attachment; filename="' $filetodownload '"');
            
    readfile($filetodownload);
            die();
        }
    }
    else{
        echo 
    'You must login to download the file.';

    And in your article or blog content add something below link
    http://www.yoursite.com/download.php...ame=myfile.pdf instead of direct file url/path.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use mod_rewrite to redirect all requests for .pdf files to a PHP script. That script looks at the session to determine whether to show the "sign in to download" message, or send the appropriate headers and pass the PDF data through.

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:


    It seems there are two threads for the same problem posted by same user.
    http://www.sitepoint.com/forums/showthread.php?t=659863
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Threads merged

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Thanks for all your replies,

    I hve done the same with the help of jquery.

    here is my code for your view.

    <?php
    if(isset($_SESSION['id']) != true ){
    print "<script>";
    print "$(document).ready(function(){";
    print "$('#pdfdownloads a').click(function(event) {";
    print "event.preventDefault();";
    print "alert('Sign in to download');";
    print "});";
    print "});";
    print "</script>";
    }
    ?>

    Thank you Very much for all of your efforts.

  8. #8
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I've done a bunch of stuff like this, and I suggest using a slightly different approach that simplifies the process:
    You can circumvent the need to create user registration by simply using a form where users enter a form and check off the documents they want to download. Then use PHPMailer to send the documents. You can log the users email or send it to yourself at the same time.

    Of course, the documents have to be small enough.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •