Page 1 of 1

tutorial for php and forms

Posted: Sun Mar 14, 2004 8:48 pm
by anmol
tutorial

Posted: Sun Mar 14, 2004 8:57 pm
by tim
if you dont want to intergrate any databases/anything, how do you plan on storing the users name n password?

Code: Select all

<?php
<form action=log.php method=POST>
<input type=text name=var_name>
<input type=text name=var_pass>
<input type=submit value=Submit>

?>
you can echo all the above, and the name in field one would have a variable name $var_name and when the user clicks submit, it will take them to a log.php page where u can use a simple if-statement could validate whether or not a user has type the correct password of not but I cant help you there cause i dont know how u plan on storing the names/passwords.

this is only a idea of how to do it but you need to figure out whtat u want to do to store the names

Posted: Sun Mar 14, 2004 8:58 pm
by d3ad1ysp0rk
page they login from:

Code: Select all

&lt;html&gt;
&lt;body&gt;
&lt;form action="login.php" method="post"&gt;
Username: &lt;input type="text" name="username"&gt;
Password: &lt;input type="password" name="password"&gt;
&lt;input type="submit" name="submit" value="Login"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
login.php

Code: Select all

<?PHP
session_start();
if($_POST['username']=="anmol" || $_POST['password']=="password"){
$_SESSION['username'] = $_POST['username'];
}
else {
echo "Incorrect Username or Password!";
}
?>
Then on any page you want to check if they're logged in:

Code: Select all

<?PHP
session_start();
if($_SESSION['username']=="anmol"){
//do stuff for logged in ppl
}
else {
//do stuff for ppl that aren't logged in
}
?>

Posted: Sun Mar 14, 2004 9:04 pm
by tim
that works if you want to assign everyones account as a variable for their name n password(you manually have to create them). if thats what you wanted, i'm sorry for misunderstanding.

hi

Posted: Sun Mar 14, 2004 9:30 pm
by anmol
no i just wanted to use values assigned to variables as user name and password and no sql database stuff