PDA

View Full Version : Login script


v-design
04-16-2001, 08:53 PM
Hi everybody,

Can someone help me with creating a login script?

What i basically need is a html page that contains a form txt field where users have to fill in their name and the form checks the name from a plain txt file and then redirects them to their URL.

The text file should have multiple lines e.g.

Name=test; URL=http://www.test.html

What this does is when the user fills in "test" and presses the submit button, the form checks if the word "test" is in the list and if it is there it goes to the link that is specified after the test word in the text file.

I've looked everywhere almost on the net, but i can't seem to find it.

DarkWizard
04-16-2001, 09:13 PM
Give me time to think about this one...I have to pack and head out of town for a few days but will look into it when I get back...

v-design
04-16-2001, 09:41 PM
Cool Darkwizard, thanks. I am almost hopeless. I posted on several boards this request but no one seems to reply.

It should be really easy to set it up but i cant seem to find anything to help me out.

Odium
04-16-2001, 09:55 PM
I wrote a very simple PHP script (emphasis on "simple") a couple of weeks ago that does something similar to what you want...it could probably be modified to do exactly what you want, I guess, but I'm too much of a newbie at PHP to modify it for you.

Basically what I did was make a script that redirects users to specific URLs based on what they type in a form's text field. For example, if someone types in dog and submits the form, they might get redirected to dog.html, and so on...if they type in a keyword that isn't listed as a variable in the script, they get redirected to a custom error page. It's very easy to modify and add more keyword variables... Like I said, really simple...is that along the lines of what you're looking for? Someone who knows more about PHP (and writing scripts in general, I'm no expert whatsoever) could probably use this same idea I had and make it do what you want....

bianca
04-17-2001, 01:45 AM
i would use php with sessions which is quite easy to do cause if someone knows the direct url u have NO way of stoping them as u are not performing a check against it...

or

use could use htaccess file to do it :)

allen
04-17-2001, 02:43 AM
The Form
------------

<FORM METHOD=post ACTION="thescript.php">
<input type="text" name="username">
<input type=submit>
</FORM>

__________________________________________


The Processing Script
---------------------------
<?php

$filelines = file('thefile.txt'); // reads all lines from the file with the info into an array

foreach($file as $aline){ //for each array item
$pieces = explode(";",$aline); // split the line into an array at the semi-colon sign

$name = substr($pieces[0],6); //extracts the substring beginning from character 6 (Name=t) - t is sixth
$url= substr($pieces[1],5); //extracts the substring beginning from character 5 (URL=h) - h is fifth

if($username==$name){ //if name matches inputted username , then redirect
header("location:$url");
}

}

header("location=default.html"); //if above code is run without matches , redirect to a default

?>

_________________________________________


I hope this code helps. I havent tested it though. Personally this would be way too inefficient a way for me. What happens when you reach one thousand people?? Instead,I would either

1.Use a DB , much much faster and easier since i dont have to iterate through each line (which isnt actually neccesary even with a flat file, but im really too lazy right now to post an example). Using a DB is such a happy experience, trust me. :)

2.OR , at worst case , make the file structure into

name ; http://something.com ,

which is much easier to parse.

v-design
04-17-2001, 07:05 AM
Hey Allen, yeah that is possible, but i do not have any experience with PHP but what you just described is exactly what i mean.

I do not have any experience with databases so maybe someone can help me setting it up for me

allen
04-17-2001, 01:47 PM
Sure, ill post one if i have time.