Follow along with the video below to see how to install our site as a web app on your home screen.
Бележка: This feature may not be available in some browsers.
<?php
session_start();
ob_start();
$dbhost = "localhost";
$dbuser = "user";
$dbpass = "pass";
$dbname = "database";
mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
?>
<?php
include_once "config.php";
if (!isset($_SESSION['username']))
{
?>
<form method="POST">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Register">
</form>
<?php
if (isset($_POST['submit']))
{
$user = addslashes(htmlspecialchars($_POST['username']));
$pass = addslashes(htmlspecialchars($_POST['password']));
if (!empty($user) and !empty($pass))
{
$newpass = md5($pass);
mysql_query("INSERT INTO users (username,password) VALUES ('$user','$newpass')") or die(mysql_error());
header('Location: login.php');
}
else
{
echo "error";
}
}
}
else
{
header('Location: index.php');
}
?>
<?php
include_once "config.php";
if (!isset($_SESSION['username']))
{
?>
<form method="POST">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Login">
</form>
<?php
if (isset($_POST['submit']))
{
$user = addslashes(htmlspecialchars($_POST['username']));
$pass = addslashes(htmlspecialchars($_POST['password']));
if (!empty($user) and !empty($pass))
{
$newpass = md5($pass);
$a = mysql_query("SELECT * FROM users WHERE username='$user' and password='$newpass'") or die(mysql_error());
$b = mysql_num_rows($a);
if ($b > 0)
{
$_SESSION['username'] = $user;
header('Location: index.php');
}
else
{
echo "error";
}
}
else
{
echo "error";
}
}
}
else
{
header('Location: index.php');
}
?>
<?php
include_once "config.php";
if (!isset($_SESSION['username']))
{
?>
<a href="login.php">Login</a> | <a href="register.php">Register</a><br>
<?php
}
else
{
echo "Hello ".$_SESSION['username'];
}
?>
bancov96 каза:Като нищо ще ти източат данните на потребителите и да ти изтрият всичко с тая система. Едни addslashes() не се сложили даже...
<?php
include_once "config.php";
if (!isset($_SESSION['username']))
{
?>
<form method="POST">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Register">
</form>
<?php
if (isset($_POST['submit']))
{
$user = addslashes(htmlspecialchars($_POST['username']));
$pass = addslashes(htmlspecialchars($_POST['password']));
if (!empty($user) and !empty($pass))
{
$a = mysql_query("SELECT * FROM users WHERE username='$user'") or die(mysql_error());
$b = mysql_num_rows($a);
if ($b > 0)
{
echo "zaeto ime";
}
else
{
$newpass = md5($pass);
mysql_query("INSERT INTO users (username,password) VALUES ('$user','$newpass')") or die(mysql_error());
header('Location: login.php');
}
}
else
{
echo "error";
}
}
}
else
{
header('Location: index.php');
}
?>
<?php
include_once "config.php";
if (!isset($_SESSION['username']))
{
?>
<form method="POST">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Register">
</form>
<?php
if (isset($_POST['submit']))
{
$user = addslashes(htmlspecialchars($_POST['username']));
$pass = addslashes(htmlspecialchars($_POST['password']));
if (!empty($user) and !empty($pass))
{
$a = mysql_query("SELECT * FROM users WHERE username='$user'") or die(mysql_error());
$b = mysql_num_rows($a);
if ($b > 0)
{
echo "zaeto ime";
}
else
{
$newpass = md5($pass);
mysql_query("INSERT INTO users (username,password) VALUES ('$user','$newpass')") or die(mysql_error());
header('Location: login.php');
}
}
else
{
echo "error";
}
}
}
else
{
header('Location: index.php');
}
?>
<?php
include_once "config.php";
if (!isset($_SESSION['username']))
{
?>
<form method="POST">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Register">
</form>
<?php
if (isset($_POST['submit']))
{
$user = addslashes(htmlspecialchars($_POST['username']));
$pass = addslashes(htmlspecialchars($_POST['password']));
if (!empty($user) and !empty($pass))
{
$newpass = md5($pass);
mysql_query("INSERT INTO users (username,password) VALUES ('$user','$newpass')") or die(mysql_error());
header('Location: login.php');
}
else
{
echo "error";
}
}
}
else
{
header('Location: index.php');
}
?>
proba каза:database.sql
[sql]
CREATE TABLE `users`
(
`id` int(11) NOT NULL auto_increment,
`username` text character set utf8 NOT NULL,
`password` text character set utf8 NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE=MyISAM AUTO_INCREMENT=0 ;
[/sql]
config.php
PHP:<?php session_start(); ob_start(); $dbhost = "localhost"; $dbuser = "user"; $dbpass = "pass"; $dbname = "database"; mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); ?>
register.php
PHP:<?php include_once "config.php"; if (!isset($_SESSION['username'])) { ?> <form method="POST"> Username: <input type="text" name="username"><br> Password: <input type="password" name="password"><br> <input type="submit" name="submit" value="Register"> </form> <?php if (isset($_POST['submit'])) { $user = addslashes(htmlspecialchars($_POST['username'])); $pass = addslashes(htmlspecialchars($_POST['password'])); if (!empty($user) and !empty($pass)) { $newpass = md5($pass); mysql_query("INSERT INTO users (username,password) VALUES ('$user','$newpass')") or die(mysql_error()); header('Location: login.php'); } else { echo "error"; } } } else { header('Location: index.php'); } ?>
login.php
PHP:<?php include_once "config.php"; if (!isset($_SESSION['username'])) { ?> <form method="POST"> Username: <input type="text" name="username"><br> Password: <input type="password" name="password"><br> <input type="submit" name="submit" value="Login"> </form> <?php if (isset($_POST['submit'])) { $user = addslashes(htmlspecialchars($_POST['username'])); $pass = addslashes(htmlspecialchars($_POST['password'])); if (!empty($user) and !empty($pass)) { $newpass = md5($pass); $a = mysql_query("SELECT * FROM users WHERE username='$user' and password='$newpass'") or die(mysql_error()); $b = mysql_num_rows($a); if ($b > 0) { $_SESSION['username'] = $user; header('Location: index.php'); } else { echo "error"; } } else { echo "error"; } } } else { header('Location: index.php'); } ?>
index.php
PHP:<?php include_once "config.php"; if (!isset($_SESSION['username'])) { ?> <a href="login.php">Login</a> | <a href="register.php">Register</a><br> <?php } else { echo "Hello ".$_SESSION['username']; } ?>
Сега я писах и не съм я пробвал , ако има проблеми казвай![]()