Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- try {
- $db = new PDO("mysql:dbname=dt003514798", "dt003514798", "uN0nei1N");
- } catch (PDOexception $e) {
- echo "Greska kod spajanja na bazu: " . $e->getMessage();
- }
- $db->exec("SET NAMES utf8");
- if (isset($_POST['usr_register'])) {
- //enter podatke u bazu
- $qdodaj = $db->prepare("INSERT INTO users (username, password) VALUES (?, ?)");
- if (isset($_POST['usr_name']) && isset($_POST['usr_pwd'])) {
- $qdodaj->execute(array(
- $_POST['usr_name'], sha1($_POST['usr_pwd'])
- ));
- }
- }
- if (isset($_POST['usr_login'])) {
- //check podatke iz baze
- $q_check = $db->prepare("SELECT * FROM users WHERE username = :username AND password = :password");
- $q_check->bindValue(':username', $_POST['username'], PDO::PARAM_STR);
- $q_check->bindValue(':password', sha1($_POST['password']), PDO::PARAM_STR);
- $q_check->execute();
- $data = $q_check->fetchAll();
- if (!empty($data)) {
- $_SESSION['user_id'] = $data['id'];
- var_dump($data);
- }
- }
- if (!isset($_SESSION['user_id'])) {
- header("Location: login.php");
- } else {
- ?>
- <html>
- <form action="zad2.php" method="post">
- <input type="submit" value="odlogiraj se!" name="usr_logoff"/>
- </form>
- <?
- }
- if (isset($_POST['sess_dstr'])) {
- session_destroy();
- $_SESSION = array();
- }
- ?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement