logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 06-11-2007, 07:48 AM   #1
Karkar
Karkar's Avatar
 
Join Date: Apr 2007
Location: Melbourne, Australia
Posts: 173
Default log in, log out help

My script wont launch. I have a feeling it has something to do with the way I wrote this:

session_start();
if (! isset($_SESSION['id'])){
header("location: login.php");
exit;
}
$id = $_SESSION['id'];

Is that right??
Karkar is offline   Reply With Quote
Old 06-11-2007, 09:06 AM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

is this the security.php
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 06-11-2007, 09:10 AM   #3
Karkar
Karkar's Avatar
 
Join Date: Apr 2007
Location: Melbourne, Australia
Posts: 173
Default

not hats welcome.php
Karkar is offline   Reply With Quote
Old 06-11-2007, 09:14 AM   #4
Karkar
Karkar's Avatar
 
Join Date: Apr 2007
Location: Melbourne, Australia
Posts: 173
Default

Welcoem.php


PHP Code:
<?php
require_once("connections/connection.php"); // database connection
session_start();
if (! isset(
$_SESSION['id'])){
header("location: login.php");
exit;
}
$id $_SESSION['id'];
/////////////////////
$query sprintf("SELECT * FROM users where user_id='$id' "); 
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
/////////////////////
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
Welcome to the application, <?php echo $rowAccount['user_name'];?>
</body>
</html>
login.php

PHP Code:
<?php
require_once("connections/connection.php"); // database connection
session_start();
$userid $_POST['userid'];
$password $_POST['password'];
$submitted $_POST['submitted'];
if (
$userid && $password) {
/////////////////////
$query sprintf("SELECT * FROM users where user_name='$userid' and user_password = '$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
/////////////////////
}
if (
$rowAccount) {
$_SESSION['id'] = $rowAccount['user_id'];
header("location: welcome.php");
exit;
}elseif (
$submitted){
echo 
"Go away !!";
}
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="309" height="211" border="1" align="center">
<tr>
<td width="106">User ID </td>
<td width="143"><label>
<input name="userid" type="text" id="userid" />
</label></td>
</tr>
<tr>
<td>Password</td>
<td><label>
<input name="password" type="text" id="password" />
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="submitted" type="hidden" id="submitted" value="1" />
<label>
<input type="submit" name="Submit" value="Submit" />
</label></td>
</tr>
</table>
</form>
</body>
</html>
Karkar is offline   Reply With Quote
Old 06-11-2007, 09:21 AM   #5
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

whats happening K

is it not loggin in
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 06-11-2007, 11:22 AM   #6
Karkar
Karkar's Avatar
 
Join Date: Apr 2007
Location: Melbourne, Australia
Posts: 173
Default

it shows the form with these error messages.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Documents and Settings\Alex\My Documents\web root\test\connections\connection.php:12) in C:\Documents and Settings\Alex\My Documents\web root\test\login.php on line 4

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Documents and Settings\Alex\My Documents\web root\test\connections\connection.php:12) in C:\Documents and Settings\Alex\My Documents\web root\test\login.php on line 4

When I attempt to login it shows these error messages:

Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\Alex\My Documents\web root\test\connections\connection.php:12) in C:\Documents and Settings\Alex\My Documents\web root\test\login.php on line 22
Karkar is offline   Reply With Quote
Old 06-11-2007, 11:31 AM   #7
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

where you have this...
PHP Code:
echo "Go away !!"
assign this to a variable

dont echo anything above html

try this then run it again
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 06-11-2007, 01:33 PM   #8
Karkar
Karkar's Avatar
 
Join Date: Apr 2007
Location: Melbourne, Australia
Posts: 173
Default

i dont quite understand what you mean. why would i assign this to a variable. I dont beleive this is what you did inthe tutorial?
Karkar is offline   Reply With Quote
Old 06-11-2007, 01:44 PM   #9
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

yes it is what i did. The tutorial were the basics. Now its time to progress up a level

The error your getting is reference to header output. if some text is echo'd befor the HTML is sent then you could get an error plus you want to have total control over your code and what echo's where. By assigning the message to a var like this...
PHP Code:
$warning "Go away !!"
it means you can echo $warning anywhere on the screen you want rather than having it display above everything like your container or banner

does this makes sense
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 06-11-2007, 02:00 PM   #10
Karkar
Karkar's Avatar
 
Join Date: Apr 2007
Location: Melbourne, Australia
Posts: 173
Default

this does not seem to solve the header problem though.

If assigning this avariable like this :

elseif ($submitted){
echo $warning = "Go away !!";

}
would i then need to add it here:

session_start();
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
...........
Karkar is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:04 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com