Page 1 of 2
adding a login onto a different page
Posted: Fri Feb 11, 2005 1:29 pm
by Smackie
Alright like i said i made a login script. but i want to use that login on a different page like say my index.php page alright well when i add it to the codes i use
but everytime i login it sends me to the same page but on the url it gives me
"url"?username=username&password=userpassword
is there a way someone can help me put it on that page without having this trouble?
Thank you
Smackie
~At last there will be a end to everything when thy Smackie returns to thy Kingdom and wipes out every thing in site.. Death 12:3~
Posted: Fri Feb 11, 2005 1:30 pm
by timvw
what is the method in your form...
<form action="url_of_script" method="post">
Posted: Fri Feb 11, 2005 1:33 pm
by Smackie
Code: Select all
<form action="?op=login" method="POST">
Posted: Fri Feb 11, 2005 1:34 pm
by timvw
then you have to show us the contents of login.php.....
Posted: Fri Feb 11, 2005 1:36 pm
by Smackie
you mean add all the login scripts to the index file?
Posted: Fri Feb 11, 2005 2:12 pm
by timvw
no, i mean: post the contents of login.php in this forum......
because in the code you've shown untill now is nothing wrong (as far as i can see)
Posted: Fri Feb 11, 2005 2:21 pm
by Smackie
here it is the login.php
Code: Select all
<?php
session_start();
// dBase file
include "dbConfig.php";
if ($_GETї"op"] == "login")
{
if (!$_POSTї"username"] || !$_POSTї"password"])
{
die("Please go back and Supply a username and password.");
}
// Create query
$q = "SELECT * FROM `dbUsers` "
."WHERE `username`='".$_POSTї"username"]."' "
."AND `password`=PASSWORD('".$_POSTї"password"]."') "
."LIMIT 1";
// Run query
$r = mysql_query($q);
if ( $obj = @mysql_fetch_object($r) )
{
// Login O.K., create session variables
$_SESSIONї"valid_id"] = $obj->id;
$_SESSIONї"valid_user"] = $_POSTї"username"];
$_SESSIONї"valid_time"] = time();
// Redirect to member page
Header("Location: members.php");
}
else
{
// Login not successful
die("Sorry, could not log you in. Wrong login information.");
}
}
else
{
include "colors.html";
echo "<form action="?op=login" method="POST">";
echo "Username: <input name="username" size="15"><br />";
echo "Password: <input type="password" name="password" size="15"><br />";
echo "<input type="submit" value="Login">";
echo "</form>";
}
?>
...
Posted: Sat Feb 12, 2005 1:21 pm
by s.dot
include this on the page that you're trying to include the login file on.
Code: Select all
<?
// See if they're logging in, if they are, direct to login page //
<? if($action == "login") {
header ("Location: loginpage.php?op=login"); }
?>
<form action="<? echo $PHP_SELF; ?>" method="post">
<input type="hidden" name="action" value="login">
// login form fields here //
<input type="submit" value="Login">
</form>
Posted: Sat Feb 12, 2005 5:20 pm
by Smackie
That didnt help

i would like to add the whole script in there but it starts out like
and i always get a Warning that says
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/smackie/public_html/smackie/index.33.php:9)
in /home/smackie/public_html/smackie/index.33.php on line 164
For some reason my php login code session start(); dont like to leave its little spot on line 2

anyone have an idea why it does that?? please help
Posted: Sat Feb 12, 2005 5:28 pm
by feyd
did you read into why that is said? you have text output before the php tags start..
Posted: Sat Feb 12, 2005 5:39 pm
by Smackie
What do you mean i got text outputs before the php tags start?
see my test index page is html but i want to add my login page which is php..
so i named my test index page index33.php so that i could add my php login script there but how would i make it where it would work or whatever?
Posted: Sat Feb 12, 2005 6:30 pm
by s.dot
u must have all header information put before any HTML or text is printed to the browser. In addition, if the page you're adding this script into has a session_start() you'll probably see that error. You only need one session start per page.
Posted: Sat Feb 12, 2005 6:31 pm
by shiznatix
use
as line 1 of your code, ok flame me now. i donno what it does but it makes those errors go away and everything works
Posted: Sat Feb 12, 2005 6:41 pm
by Smackie
Thanx for the
Part it works but yet it still wont take me to the place i want it to take me to it still stays there just gives me a
index33.php?username=username&password=userpassword
how am i going to makie it go to where i want it to go???
Posted: Sat Feb 12, 2005 6:47 pm
by shiznatix
so it dosnt redirect you to members.php at all or it does but the url just is
members.php?username=username&password=userpassword
???