Results 1 to 8 of 8

Thread: Login Script

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Login Script

    Hi

    I am looking for an logic about user login. I am developing a website where a visitor can surf and search the website. But if he wants to download a file from the site, he has to sign in or register as a new user.

    Can someone explain the how to do it or a sample ASP script.


    Thanks

  2. #2
    Member
    Join Date
    Apr 2004
    Posts
    59
    You could do something like this:

    1. create a database which will store user registration information e.g. nickname, first name, second, address etc

    2. create a login screen which compares the values entered into the username and password textboxes with the values in the database

    3. store this info in a session so it can keep track of the user has he/she moves through the pages.

    I think I made it sound easier that it actually is

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253
    hi Narmi


    Thanks for your reply. Perhaps you did not get my question. My question is that a surfer can search my site without login and he can clicked a link from search result to download or see the files. How can I check he is logged in or not when he clicks to download or see the file.


    Hope I made my question clear.


    Thanks

  4. #4
    Member
    Join Date
    Apr 2004
    Posts
    59
    Thats where the "session" variable comes into play. Look at Number 3 in my first post.

    Once the user has logged in, You could say something like:

    psydo code

    Code:
    if session == any username in the database then
         download file
    else
         do something else
    end if

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253
    hi Narmi

    Sorry for my foolish questions.

    Let say a surfer has searched my site and he got following results:

    1. ABC
    2. 123
    3. XYZ

    Now if he clicks on any link from the result. How can I use that IF statement here. I am very much new in ASP.


    Thanks

  6. #6
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Hi,

    To display the links, I am assuming, you have made a search script which searches your site/database and then the links are displayed.

    At the time of displaying the links, you just have to put in the if cluase something like this:

    Code:
    'Results of the search script being displayed using a do While
    ' the If condition
    
    If Session("Username") = "" Then
         'Give the link to the login page instead of the actualy file 
    Response.Write("<a href="/Login.aspx?f=theFilename.ext">FileName</a>")
    Else
        'give the link to the download file
        Response.Write("<a Href='somepath/filename.ext'>FileName</a>")
    End if
    I hope this helps

    PS: I dont have studio on this machine, so wasnt able to write a "neat" code.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253
    hi Johnny

    Thanks for your input. But I am very much new in ASP. I have written a small search script. How can I incorporate your code in mine and don't you think it's better to check user login in a separate file and include that file in all the downloadable page.


    Thanks

  8. #8
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    of course, you will have the login script on another page.

    I guess, you are using a SQL to fetch the records from the table on users criteria, and then using a loop to display the records, thats when u need to insert that IF condition and give the link to the Login page, where the User would either login or register as a new user.

    helps?

Posting Permissions

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



Click Here to Expand Forum to Full Width