Neke od polja u mysql-u sam dodao sam.
Ovo u sledeći filov-i.Zapravo koristeci ove skripte registrujem user-e i
da mogu da pristupe members.php stranici.
Ovo je moja index1.php stranica..
<?php
// Connects to your Database
mysql_connect(„localhost”, „root”, „”) or die(mysql_error());
mysql_select_db(„users”) or die(mysql_error());
//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
//if there is, it logs you in and directes you to the members page
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query(„SELECT * FROM users WHERE username = '$username'”)or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header(„Location: members.php”);
}
}
}
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query(„SELECT * FROM users WHERE username = '”.$_POST['username'].„'”)or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database.
<a href=register1.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Incorrect password, please try again.');
}
else
{
// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
//then redirect them to the members area
header(„Location: members.php”);
}
}
}
else
{
// if they are not logged in
?>
<div id="login">
<form action=„<?php echo $_SERVER['PHP_SELF']?>” method=„post”>
Username:
<input type="text" name="username" maxlength="40">
Password:
<input type="password" name="pass" maxlength="50">
<input type="submit" name="submit" value="Login">
</div>
<?php
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Computer Parts LTD</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="Author Name - University of Central England in Birmingham" />
<link rel="stylesheet" href="./style/main.css" type="text/css" media="screen" title="main" />
<!--
Author: Marko Radisa
Organisation: School of Computing and Information, University of Central England in Birmingham
Web Site: http://ares.students.uce.ac.uk/~dnnnnnnnn
Email: [email protected]
Copyright: Copyright Author Name 2004
-->
</head>
<body>
<div id="header">
Your Action:
<a href="./login1.html" name="">Sign In</a>
<a href="./register1.html" name="">Register</a>
</div>
<div id="mainmenu">
<a href="">Home</a>
<a href="">Home</a>
<a href="">Home</a>
<a href="">Home</a>
<a href="">Home</a>
</div>
<div id="content">
</div>
</body>
--------------------------------------------------------------------------------------------------------------------
OK ova stranica radi sasvim ok.Stavio sam php pri vrhu zato što nije stranica nije htela da radi kada je php code bio u body-u.
Naprimer kada pokusam da se login i ako su username and password tačni php skripta me prebaci na members.php
stranicu i napravi cookie.
E sada kada pokusam da pristupim member.php stranici koja izgleda ovako
---------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Computer Parts LTD</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="Author Name - University of Central England in Birmingham" />
<link rel="stylesheet" href="./style/main.css" type="text/css" media="screen" title="main" />
<!--
Author: Marko Radisa
Organisation: School of Computing and Information, University of Central England in Birmingham
Web Site: http://ares.students.uce.ac.uk/~dnnnnnnnn
Email: [email protected]
Copyright: Copyright Author Name 2004
-->
</head>
<body>
<div id="header">
Your Action:
<a href="./login.html" name="">Sign In</a>
<a href="./home.html" name="">Register</a>
</div>
<div id="mainmenu">
<a href="">Home</a>
<a href="">Home</a>
<a href="">Home</a>
<a href="">Home</a>
<a href="">Home</a>
</div>
<div id="content">
<?php
// Connects to your Database
mysql_connect(„localhost”, „root”, „”) or die(mysql_error());
mysql_select_db(„users”) or die(mysql_error());
//checks cookies to make sure they are logged in
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query(„SELECT * FROM users WHERE username = '$username'”)or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
//if the cookie has the wrong password, they are taken to the login page
if ($pass != $info['password'])
{ header(„Location: login1.php”);
}
//otherwise they are shown the admin area
else
{
echo „Admin Area<p>”;
echo „Your Content<p>”;
echo „<a href=./logout.php>Logout</a>”;
}
}
}
else
//if the cookie does not exist, they are taken to the login screen
{
header(„Location: index.php”);
}
?>
bla bla bla bla bla bla
</div>
</body>
----------------------------------------------------------------------
dobijem sledeći error
Warning: Cannot modify header information - headers already sent by (output started at C:wampwwwFirstmembers.php:8) in C:wampwwwFirstmembers.php on line 64
bla bla bla bla bla bla
Zbog čega me ovaj code ne vraca na index1.php kada nepostoji cookie?
I šta je zapravo ovaj error i kako da ga popravim.
Da li je pogresno kobinirati php code sa html-om i css?