authenticating a user before opening a document by clicking a hyperlink

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hello2008
    New Member
    • Dec 2007
    • 14

    authenticating a user before opening a document by clicking a hyperlink

    Hi,

    I am new to PHP. I need to authenticate a user before clicking the link which opens an already existing PDF file.. so that no one can just click on a link provided to him/her and open the concerned PDF without providing the correct username and password first.

    Can anyone help me with this authentication?
  • hello2008
    New Member
    • Dec 2007
    • 14

    #2
    New to PHP.. seeking some guidance

    Hi again,

    The issue is resolved now.. I tried the following:
    [PHP]
    // Code in Index.php
    <?php
    session_start() ;

    if($_SESSION)
    {
    // HTML code
    } else
    {
    echo 'Please Login First!!!' ;
    include("Login. php"); // takes the user to the Login page for authentication
    }
    ?>
    [/PHP]
    Only when the session is active can someone see the page Index.php... and at other times if someone just tries to copy-paste this page's URL in the address bar of some other window in order to open it, the control executes the code in the else part of the page thus prohibiting anyone from seeing the page without authentication!

    Thanks!!!

    P.S:-
    I am only a week old with PHP and am expected to be good at it pretty quickly since there are many projects at my firm lined up.. most of them implement PHP. Would like to know of any books / websites that offer PHP tutorials and sample projects so that I can learn and code in PHP the proper way right from the beginning ...

    Hope someone can help.. thanks in advance!!!
    Last edited by hello2008; Dec 29 '07, 08:18 AM. Reason: Adding more content to the post

    Comment

    Working...