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

Code: Select all

<?php
include "login.php";
?>
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&#1111;"op"] == "login")
                &#123;
	if (!$_POST&#1111;"username"] || !$_POST&#1111;"password"])
		&#123;
		die("Please go back and Supply a username and password.");
		&#125;

	// Create query
	$q = "SELECT * FROM `dbUsers` "
		."WHERE `username`='".$_POST&#1111;"username"]."' "
		."AND `password`=PASSWORD('".$_POST&#1111;"password"]."') "
		."LIMIT 1";
	// Run query
	$r = mysql_query($q);

	if ( $obj = @mysql_fetch_object($r) )
	&#123;
		// Login O.K., create session variables
		$_SESSION&#1111;"valid_id"] = $obj->id;
		$_SESSION&#1111;"valid_user"] = $_POST&#1111;"username"];
		$_SESSION&#1111;"valid_time"] = time();

	// Redirect to member page
	Header("Location: members.php");
                 	&#125;
	else
		&#123;
		// Login not successful
		die("Sorry, could not log you in. Wrong login information.");
		&#125;
	                &#125;
                else
		&#123;
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>";
		&#125;

?>

...

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") &#123;
header ("Location: loginpage.php?op=login"); &#125;
?>

<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

Code: Select all

<?php
session_start();
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

Code: Select all

<? ob_start(); ?>
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

Code: Select all

<? ob_start(); ?>
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

???