创建日记php应用程序 [英] Creating a diary php application

查看:50
本文介绍了创建日记php应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建日记应用程序,使人们可以登录并提交其日常日记.我创造了.我已经开始创建登录页面,一旦用户登录,他将被定向到会员页面.
我很难过的是让用户名显示在会员页面上.我不确定如何获取用户名.我一直在做PHP教程.这是我到目前为止所拥有的,希望你们中的一些人可以为我指明正确的方向.

我的login.php

HI I''m trying make a Diary application where people can log in and submit to their daily diary. I have created. I have started to create the login page and once the user is logged in he will be directed to a members page.
What Im having a hard time with is getting the users name to display on the members page. Im not sure how to get the user name. I have been doing the php tutorials. here''s what I have so far and hope some of you guys can point me to the right directions.

my login.php

<?php
include 'conn.php';

if (loggedin()==TRUE)
	header("Location: usersarea.php");

if ($_POST['login'])
{
	//get data
	$username = $_POST['username'];
	$password = $_POST['password'];
	$rememberme = $_POST['rememberme'];
	// $login = $_POST['login'];
	
	
	if ($username&&$password)
	{
	
	$login = mysql_query("SELECT * FROM users WHERE username='$username'");
	while ($row = mysql_fetch_assoc($login))
	{
		$db_password = $row['password'];
		if(md5($password)==$db_password)
		$loginok = TRUE;
		else
		$loginok = FALSE;
		if ($login==TRUE)
		{
			if($rememberme== 0)
			setcookie("username", $username, time()+7200);
			else if($rememberme== 1 )
			$_SESSION['username']=$username;
			
			header("Location: usersarea.php");
			exit();
			
		}
		else
			echo("incorrect username/password.");
		
	}
		
	}
	else{
		echo("Wrong");
	}
}

?>

<form action="login.php" method="POST" accept-charset="utf-8">
	<label for="username">username</label><br />
	<input type="text" name="username" value="" id="username">
	<br />
	<label for="password">passord</label><br />
	<br />
	<input type="text" name="password" value="" id="password">
	<br />
<label for="rememberme">rememberme</label><br />
<input type="checkbox" name="rememberme" value="" id="rememberme">

	<p><input type="submit" name="login" value="login"></p>
</form>




userarea.php




userarea.php

<?php
include ''conn.php'';

if(!loggedin())
{
	header("Location: login.php");
	exit();
}


?>
<?php
<p>$_SESSION[''username'']=$username;</p> 

?>
<p>You''re logged in!</p>
	
<a href="logout.php">Logout</a>

<pre lang="text">



conn.php



conn.php

<?php

//session_start
session_start();

//connect to my database
mysql_connect("127.0.0.1","root","") or die();
mysql_select_db("users") or die();

//login check functions
function loggedin()
{
	if(isset($_SESSION['username'])||isset($_COOKIE['username']))
	{
		$loggedin = TRUE;
		return $loggedin;
	}
}



?>





我的数据库





my db

<pre lang="text">
CREATE TABLE `users` (
  `id` int(25) NOT NULL AUTO_INCREMENT,
  `username` varchar(65) NOT NULL DEFAULT '''',
  `password` varchar(32) NOT NULL DEFAULT '''',
  `EmailAddress` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

推荐答案

_POST ['login']) { //获取数据
_POST['login']) { //get data


用户名=


_POST ['username'];
_POST['username'];


这篇关于创建日记php应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆