コード例 #1
0
function check_valid_user()
{
    //see if somebody is logged in and notify them if not
    if (isset($_SESSION['valid_user'])) {
        echo "Logged in as " . $_SESSION['valid_user'] . "<br/>";
    } else {
        //they are not logged in
        do_html_heading('Problem');
        echo 'You are not logged in.<br/>';
        do_html_URL('login.php', 'Login');
        do_html_footer();
        exit;
    }
}
コード例 #2
0
function notify_password($username, $new_password)
{
    $from = "From: support@rippedandfit.com\r\n";
    $mesg = "Your rippedandfit password has been changed to" . $new_password . "\r\n" . "Please change it on next log in!";
    if (mail($email, 'rippedandfit login information', $mesg, $from)) {
        return true;
    } else {
        do_html_URL("index.php", "Homepage");
        die('Could not send mail');
    }
    echo 'Your new password has been emailed to you - please change it on next log in!';
    do_html_URL("index.php", "Homepage");
}
コード例 #3
0
ファイル: dologin.php プロジェクト: hukaixuan/voting-system
<?php

//登录验证
require_once 'fns.php';
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username && $password) {
    try {
        login($username, $password);
        $_SESSION['username'] = $username;
    } catch (Exception $e) {
        //未能成功登录
        do_html_header('problem');
        echo '登录失败,请重试';
        do_html_URL('index.php', 'Login');
        do_html_footer();
        exit;
    }
}
//登录成功,跳转到user_main.php
header('Location:user_main.php');
l;
コード例 #4
0
ファイル: doregist.php プロジェクト: hukaixuan/voting-system
try {
    //验证所填项目是否为空,;以后做到前台!!!!
    if (!filled_out($username) || !filled_out($email)) {
        throw new Exception('有表单项未填,请返回重试');
    }
    //验证两次所填密码是否一致
    if ($password != $password2) {
        throw new Exception('密码不一致');
    }
    //判断密码长度是否合理
    if (strlen($password) < 6 || strlen($password) > 16) {
        throw new Exception('密码必须在6-16个字符之间');
    }
    //验证邮箱
    if (!valid_email($email)) {
        throw new Exception("邮箱不合法");
    }
    //尝试 注册
    register($username, $email, $password);
    $_SESSION['valid_user'] = $username;
    //登录成功显示页面
    do_html_header('Registration successful');
    echo "注册成功,";
    do_html_URL('index.php', '立即登录');
    do_html_footer();
} catch (Exception $e) {
    do_html_header('Problem');
    echo $e->getMessage();
    do_html_footer();
    exit;
}
コード例 #5
0
if ($result) {
    $_SESSION['valid_user'] = $username;
} else {
    return false;
}
if (isset($_SESSION['valid_user'])) {
    echo "<br />Logged in as " . $_SESSION['valid_user'] . ".<br />";
} else {
    //they are not logged in
    echo "<br />PROBLEM. You are not logged in.<br />";
    do_html_URL('index.php', 'Login');
    exit;
}
function do_html_URL($url, $name)
{
    //output url as link
    ?>
	<br /><a href="<?php 
    echo $url;
    ?>
"><?php 
    echo $name;
    ?>
</a><br />
<?php 
}
if ($_SESSION['valid_user']) {
    do_html_URL("member.php", "Go to member page!!!");
} else {
    echo 'Your registration failed! - Please try again';
}
コード例 #6
0
ファイル: logout.php プロジェクト: zzy1120716/PHPandMySQL
/**
 * Created by PhpStorm.
 * User: zzy
 * Date: 2015/12/21
 * Time: 22:32
 * 用户登出
 */
//include function files for this application
require_once 'bookmark_fns.php';
session_start();
$old_user = $_SESSION['valid_user'];
//store to test if they *were* logged in
unset($_SESSION['valid_user']);
$result_dest = session_destroy();
//start output html
do_html_header('Logging Out');
if (!empty($old_user)) {
    if ($result_dest) {
        //if they were logged in and are now logged out
        echo 'Logged out.<br/>';
    } else {
        //they were logged in and could not be logged out
        echo 'Could not log you out.<br/>';
    }
} else {
    //if they weren't logged in but came to this page somehow
    echo 'You were not logged in, and so have not been logged out.<br/>';
    do_html_URL('login.php', 'Login');
}
do_html_footer();
コード例 #7
0
<?php

//显示投票结果
require_once 'fns.php';
do_html_header('投票结果');
do_html_heading('投票结果');
display_vote_result();
do_html_URL('index.php', '返回主界面');
do_html_footer();
コード例 #8
0
ファイル: user_main.php プロジェクト: hukaixuan/voting-system
<?php

require_once 'fns.php';
check_is_on();
do_html_header('Home');
do_html_heading('Success, welcome ' . $_SESSION['username'] . '<br>');
do_html_URL('add_topic.php', '添加投票');
do_html_URL('vote.php', '投票');
do_html_URL('show_result.php', '查看投票结果');
display_logout();
do_html_footer();
コード例 #9
0
ファイル: dovote.php プロジェクト: hukaixuan/voting-system
    if (!is_user_voted($user_id, $topic_id)) {
        vote($user_id, $topic_id);
        //实现在user_topic表中添加项目,记录选票信息
        add_vote($topic_id, $ABC);
        //在opt表中实现选票数的增加
    } else {
        // do_html_header('投票失败');
        echo $topic_id . "号问题你已经投过票了,不能再投了" . "<br>";
        // do_html_URL('user_main.php','返回主界面');
        // do_html_footer();
        // exit;
    }
}
do_html_header('投票完成');
echo "投票完成!" . "<br>";
do_html_URL('user_main.php', '返回主界面');
do_html_footer();
?>












コード例 #10
0
ファイル: regist.php プロジェクト: hukaixuan/voting-system
<?php

require_once 'fns.php';
do_html_header('regist');
display_regist_form();
do_html_URL('index.php', '已有账号,立即登录');
do_html_footer();
コード例 #11
-1
function login($username, $passwd)
{
    //check username and password with db
    //if yes return true
    //else throw exception
    //connect to db
    include 'db_fns.php';
    if (!$conn) {
        die . mysqli_error();
    } else {
        $username = $_POST['username'];
        $passwd = $_POST['passwd'];
        $username = stripslashes($username);
        $passwd = stripslashes($passwd);
        $username = mysqli_real_escape_string($conn, $username);
        $passwd = mysqli_real_escape_string($conn, $passwd);
        //check if username is unique
        $result = mysqli_query($conn, "SELECT username, passwd FROM usertable WHERE username='******' AND passwd=sha1( '" . $passwd . "') ") or die("Query failed." . mysqli_error());
        $row = mysqli_num_rows($result);
        if ($row == 1) {
            session_start();
            $_SESSION['valid_user'] = $username;
            ob_end_clean();
            header("Location: member.php");
            exit;
        } else {
            die('Could not log you in. Username invalid.');
            do_html_URL('index.php', 'Login');
            exit;
        }
    }
}