adding a login onto a different page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

adding a login onto a different page

Post 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~
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

what is the method in your form...

<form action="url_of_script" method="post">
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

Code: Select all

<form action="?op=login" method="POST">
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

then you have to show us the contents of login.php.....
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

you mean add all the login scripts to the index file?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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)
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post 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;

?>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

...

Post 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>
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

did you read into why that is said? you have text output before the php tags start..
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post 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???
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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

???
Post Reply