PDA

Click to See Complete Forum and Search --> : Login Script


sillylady
Jul 4th, 2004, 06:17 AM
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

narmi2
Jul 4th, 2004, 10:39 AM
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 :)

sillylady
Jul 5th, 2004, 01:38 AM
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

narmi2
Jul 5th, 2004, 02:56 AM
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


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

sillylady
Jul 5th, 2004, 03:33 AM
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

veryjonny
Jul 6th, 2004, 05:53 AM
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:


'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.

sillylady
Jul 6th, 2004, 11:50 PM
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

veryjonny
Jul 7th, 2004, 03:23 AM
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?