- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试创建一个脚本,让您登录并使用与我的用户名相同的表中的一组用户代码创建一个 session 。
每个用户代码与每个用户名不同,因为每个用户代码将在我的 index.php 上显示不同的数据
我正在使用以下代码来验证我的用户并分配他们的用户代码:
<?php
include ("include/dbConfig.php");
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect($db_hostname, $db_username, $db_password)or die("cannot connect"); // no quotes needed around vars
mysql_select_db($db_database)or die("cannot select DB"); // no quotes needed around vars
$username = mysql_real_escape_string($_POST['username']);
$encrypted_password = mysql_real_escape_string(md5($_POST['password']));
$sql="SELECT username, password FROM $tbl_name WHERE username='$username' and password='$encrypted_password'";
$sql2="SELECT usercode FROM $tbl_name WHERE usercode='$usercode'";
$result=mysql_query($sql);
$result2=mysql_query($sql2);
$sql2= $usercode1['usercode'];
// If result matched $username and $password, table row must be *AT LEAST* 1 row
if(mysql_num_rows($result)){
session_start();
$_SESSION['isamsdata']->UserCode) != ''; //This needs fixing - array
header("Location: index.php?logged in successfully");
} else {
header("Location:login.php?msg=email or password wrong");
}
?>
我的 index.php:
<?php
error_reporting(E_ALL);
session_start();
//$_SESSION['isamsdata']->UserCode = 'test';
unset($_SESSION['child_id']);
unset($_SESSION['child_first_name']);
require_once('include/newuserfunction.php');
if (isset($_SESSION['isamsdata']) AND $_SESSION['isamsdata'] != '') {
include "header.php";
include "topmenu.php";
include "leftmenu.php";
?>
<?php
include 'helpBox.php';
?>
<!-- BEGIN PAGE -->
<div class="page-content">
<!-- BEGIN PAGE CONTAINER-->
<div class="container-fluid">
<!-- BEGIN PAGE HEADER-->
<div class="row-fluid">
<div class="span12">
<!-- BEGIN PAGE TITLE & BREADCRUMB-->
<h3 class="page-title">
Parent Dashboard
<small>This is your dashboard.</small>
<button class="btn orange" style="float: right; width: 150px;" id="addpupil" onclick="showhidepupilbox();" >Add Pupil</button>
</h3>
<ul class="breadcrumb">
<li>
<i class="icon-home"></i>
<a href="index.php">Home</a>
<i class="icon-angle-right"></i>
</li>
<li><a href="#">Dashboard</a></li>
<!--<button style="float: right; background-color:green; color: white !important; margin: -1px 9px 0px 0px; border: none;" onclick="addChild();">Add Child</button>-->
</ul>
<!-- END PAGE TITLE & BREADCRUMB-->
</div>
</div>
<?php
if(isset($_GET['status']))
{
if($_GET['status'] == 1) {
echo '<div class="alert alert-success">
<button class="close" data-dismiss="alert"></button>Pupil Added Successfully. </div>';
} else {
echo '<div class="alert alert-error">
<button class="close" data-dismiss="alert"></button>Pupil Not Added Successfully. </div>';
}
}
?>
<div class="row-fluid" id="addpupilform" style="display: none;" >
<div class="span12">
<div class="portlet box orange-steel">
<div class="portlet-title">
<h4><i class="icon-table"></i>Add Pupil</h4>
</div>
<div class="portlet-body">
<div class="portlet-body form">
<form action="insert-child.php" id="add_user" class="form-horizontal add_user" method="post" name="childform">
<div class="alert alert-error hide">
<button class="close" data-dismiss="alert"></button>
You have some form errors. Please check below. </div>
<div class="alert alert-success hide">
<button class="close" data-dismiss="alert"></button>
Your form validation is successful! </div>
<div class="control-group">
<label class="control-label">First Name<span class="required">*</span></label>
<div class="controls">
<input type="text" maxlength="15" name="first_name" data-required="1" class="span6 inputfields m-wrap popovers field_autosave required" />
</div>
</div>
<div class="control-group">
<label class="control-label">Last Name<span class="required">*</span></label>
<div class="controls">
<input type="text" maxlength="15" name="last_name" data-required="1" class="span6 inputfields m-wrap popovers field_autosave required" />
</div>
</div>
<div class="control-group">
<label class="control-label">Date Of Birth<span class="required">*</span></label>
<div class="controls">
<input type="text" maxlength="15" name="dob" data-required="1" class="span6 inputfields m-wrap popovers field_autosave required" />
</div>
</div>
<div class="form-actions" style=" padding-left: 12px;">
<button type="submit" class="btn orange" >Add</button>
</div>
</form>
<!--- close body-form-->
</div>
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div class="clearfix"></div>
<div class="rows">
<div class="span12">
<div class="portlet box orange-steel">
<div class="portlet-title">
<h4><i class="icon-table"></i>Pupil's Details</h4>
</div>
<div class="portlet-body">
<!--<div class="scroller" style="height: 300px;" data-always-visible="1" data-rail-visible="0">-->
<div class="portlet-body">
<?php if(getUserChilds($_SESSION['isamsdata']->UserCode) != '') { ?>
<table class="table table-striped table-bordered table-hover" id="sample_2">
<thead>
<tr>
<th >First Name</th>
<th>Last Name</th>
<th>Date Of Birth</th>
<th>Change Details</th>
<th>Progress</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
echo getUserChilds($_SESSION['isamsdata']->UserCode);
?>
</tbody>
</table>
<?php } else { ?>You have not setup any pupil account currently, please fill the form by clicking the Add Pupil icon above.<?php } ?>
</div>
</div>
<!-- scroller </div>-->
</div>
</div>
<!-- End Rows-->
</div>
<!-- Close Div span12-->
</div>
<!-- Close Row-span12 -->
</div>
<!-- Close Row-fluid -->
<div class="row-fluid">
<div class="span12">
<div class="clearfix"></div>
<div class="rows">
<div class="span12">
<div class="portlet box orange-steel">
<div class="portlet-title">
<h4><i class="icon-table"></i>Welcome Parent</h4>
</div>
<div class="portlet-body">
<!--<div class="scroller" style="height: 300px;" data-always-visible="1" data-rail-visible="0">-->
<div class="portlet-body">
Dear <i><?php echo $_SESSION['parentdetails']->title;?> <?php echo $_SESSION['parentdetails']->firstName;?> <?php echo $_SESSION['parentdetails']->surname;?>,</i><br><br>
<p>
A very warm welcome to the on-line joining forms and thank you so much for logging on. We know there's a lot to do here but we hope that completing these on-line forms will be relatively easy and stress-free. Simply enter the name of your son or daughter above by clicking on the ‘add pupil’ tab at the top right hand corner of this page and then click ‘Fill form’.
</p>
<p>
The fields which contain a red asterisk symbol must be completed. All updates to the forms are automatically saved so you can return to the on-line joining forms at any time to complete your submissions.
</p><p>
We recommend that you have a copy of the new parents' Joining Booklet in front of you whilst completing these forms. Don't worry if you haven't, because you can access a PDF of the <a href="#" target="_blank">Joining Booklet 2014 here</a>. Information and help icons are available on all the forms in case you need guidance and, if you are still stuck, please do not hesitate to call the Admissions Office on 000000000.
</p><p>
As well as the forms, we would be very grateful if you could upload a picture of your son/daughter when prompted (this does not have to be a passport photo) and also a copy of the main page of your son or daughter's passport with all their details on it. If you do not have access to a scanner, then please feel free to send in a photocopy to Name, Registrar, at the usual School/College address.
</p><p>
I should also remind you that we do require the following to be posted in hard-copy back to the School/College:</p><p>
<ul style="width: 80%;">
<li>The Medical Forms (required) <a class="pull-right" href="#" target="_blank">Download Form</a></li>
<li>The Direct Debit Form (if appropriate) <a class="pull-right" href="#" target="_blank">Download Form</a></li>
<li>The Gift Aid Form (if appropriate) <a class="pull-right" href="#" target="_blank">Download Form</a></li>
</ul></p><p>
All forms should be completed by Monday 16th June. The information provided on these forms will be processed lawfully and fairly and held for our management and administrative purposes only.
</p><p>
I do hope that you all remain as excited about September as we are, and we look forward to seeing you all soon.
</p><p>
With best wishes,
</p><p>
Name here<br>
Director of Admissions
</p> </div>
</div>
<!-- scroller </div>-->
</div>
</div>
<!-- End Rows-->
</div>
<!-- Close Div span12-->
</div>
<!-- Close Row-span12 -->
</div>
<!-- Close Row-fluid -->
</div>
</div>
<!-- END PAGE CONTAINER-->
</div>
<!-- END PAGE CONTAINER-->
</div> <!-- END PAGE -->
<?php
include "footer.php";
} else {
header("Location:login.php");
}
?>
<script>
function showhidepupilbox()
{
console.log('Check');
jQuery('#addpupilform').toggle();
}
jQuery(document).ready(function() {
jQuery('#addpupilform').hide();
jQuery('#addpupil').click(function(){
console.log('sdf');
jQuery('#addpupilform').toggle();
});
App.setPage("table_managed"); // set current page
App.init(); // init the rest of plugins and elements
});
jQuery(document).ready(function() {
App.setPage("form_validation"); // set current page
App.init(); // init the rest of plugins and elements
});
jQuery(document).ready(function() {
});
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>
我是 PHP 和 SQL 的新手,所以任何更正都会受到尊重!
如果需要任何数据库结构,请询问。
最佳答案
可以改进/需要修复的地方:
您正在使用 mysql_,它自 php 5.5 起已弃用,不应再使用。由于您是 php 新手,现在是学习 PDO 或 mysqli_ 的最佳时机!
您正在使用 md5,不应再使用。
并且: session 开始();需要成为所有使用 session 的文件中的第一行。
我猜你正在使用你找到的教程 - 这是正确的方法,但我建议你找另一个教程。
我还没有解决 md5 问题,因为你的密码需要在数据库中更改,如果我这样做脚本将无法工作 - 但将其更改为 mcrypt
我在代码中写了一条评论 - 变量 $usercode
没有设置,我不知道它来自哪里,你可能想在第一个查询中包含 usercode/同时执行这两个操作.
这是您使用 PDO 编写的文件:
<?php
session_start();
include('include/.db_def.php');
try {
$connection = new PDO('mysql:host=' . HOST_ONE . ';dbname=' . DB_ONE , USER_ONE, PASS_ONE);
$state = $connection->prepare("SELECT username, password FROM users WHERE username = :names AND password = :password");
$state->execute(array('names' => $_POST['username'], 'password' => md5($_POST['password'])));
list ($user,$password)=$state->fetch(PDO::FETCH_NUM);
$state->closeCursor();
$state2 = $connection->prepare("SELECT usercode FROM users WHERE usercode= :usercode");
$state2->execute(array('usercode' => $usercode)); //<<< $usercode isn't set, you need to fix this
list($usercode)=$state2->fetch(PDO::FETCH_NUM);
$state2->closeCursor();
unset($connection);
if (isset($usercode) AND $usercode != '')
{
$_SESSION['isamsdata'] = $usercode;
header("Location: index.php?logged in successfully");
exit();
}
else {
header("Location:login.php?msg=email or password wrong");
exit();
}
} catch (PDOException $e) {
die('Error!: ' . $e->getMessage() . '<br/>');
}
您的 .db_def.php 应如下所示:
define('HOST_ONE','your host');
define('USER_ONE','db_user');
define('PASS_ONE','db_pass');
define('DB_ONE','db');
旁注:
我想用户代码在用户表中?如果是这样,请将查询更改为:
$state = $connection->prepare("SELECT username, password, usercode FROM users WHERE username = :names AND password = :password");
和列表之后的部分:
list ($user,$password,$usercode)=$state->fetch(PDO::FETCH_NUM);
然后您可以摆脱第二个查询!
完整代码只有一个查询:
<?php
session_start();
include('include/.db_def.php');
try {
$connection = new PDO('mysql:host=' . HOST_ONE . ';dbname=' . DB_ONE , USER_ONE, PASS_ONE);
$state = $connection->prepare("SELECT username, password, usercode FROM users WHERE username = :names AND password = :password");
$state->execute(array('names' => $_POST['username'], 'password' => md5($_POST['password'])));
list ($user,$password,$usercode)=$state->fetch(PDO::FETCH_NUM);
$state->closeCursor();
unset($state,$connection);
if (isset($usercode) AND $usercode != '')
{
$_SESSION['isamsdata'] = $usercode;
header("Location: logged_in.php?logged in successfully");
exit();
}
else {
header("Location:login.php?msg=email or password wrong");
exit();
}
} catch (PDOException $e) {
die('Error!: ' . $e->getMessage() . '<br/>');
}
?>
你的下一页应该这样开始:
<?php
session_start();
if (isset($_SESSION['isamsdata']) AND $_SESSION['isamsdata'] != '') {
// user seems to be logged in, do whatever you want here
}
else
{
header("Location:login.php?msg=you_are_not_logged_in");
exit();
}
我推荐的文件结构:
创建文件夹“views”
在 View 中,放入这个 .htaccess 文件:
<Files ~ "\.(htaccess|php)$">
order allow,deny
deny from all
</Files>
在您的根文件夹中,放入我上面写的文件并将其命名为 index.php,并为您要运行的每个文件创建以下文件,首先,将其命名为 logged_in:
<?php
session_start();
if (isset($_SESSION['isamsdata']) AND $_SESSION['isamsdata'] != '') {
include('views/logged_in.php'); //here you put the file you want to run
}
else
{
header("Location:login.php?msg=not_logged_in");
exit();
}
现在,您要运行的所有文件都必须位于“views”文件夹中,但您总是链接到根文件夹中的文件。您需要创建两个具有相同名称的文件(使它更容易),一个在根目录中,一个在 View 中。在根目录下,文件应包含行
include('views/index.php');
但是改成了你要运行的文件,f.e.
include('views/dashboard.php');
现在在“ View ”中创建文件 logged_in.php 并放入
<?= "HELLO"; ?>
进入它,看看它是否在运行。
关于php - 将 $_SESSION 设置为 MySQL 查询的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26777360/
我最近开始经常做的一件事是在任务开始时检索一些数据并将其存储在 $_SESSION['myDataForTheTask'] 中。 现在这样做似乎很方便,但我对使用这种方法的性能、安全风险或类似情况一无
我注意到人们经常简单地写 我一直在使用: 有人可以解释检查变量是否设置时的区别吗(这就是我要使用它的目的)? 最佳答案 在 PHP 中,如果变量不存在(“未设置”),则 PHP 将吐出一个 E_
我一直被这个问题逼疯了。 我正在动态创建一个 session ID,以便在刷新时保留页面状态。 如果单击了一个页面元素,我会获取该元素的 ID 并将其传递给创建 session 变量的服务器端脚本:
我试过这样做: {{ $_GET['page'] }} 但还是不行。 最佳答案 对于 $_POST 变量使用这个: {{ app.request.parameter.get("page") }} 对于
你好, 我在拼凑一个简单的登录系统时遇到了一些问题。它在 Firefox 和 Chrome 中完美运行,但对于我来说,我似乎无法在 Windows 8 的 IE10 中结束 session 。 这是我
我有一个登录表单,以 session 电子邮件开头。现在,由于我希望能够通过表单更新电子邮件地址,而不破坏 session ,因此我需要将 session 更改为 ID。问题是它不会向我发送 id 值
我想存储一些信息,例如用户名、国家/地区名称等,并且需要在整个 session 期间可用。 实现这一目标的最佳方式是什么? 我有以下代码到 $_session 变量但没有结果。 page1.php
目前,我通过将 session 中的 key 与 MySQl 数据库中的相同 key 相匹配来验证用户 session 。我使用随机数重新生成 session ,该随机数在每个页面加载时都受 MD5
我遇到了这段代码的问题,我无法弄清楚问题出在哪里。所以当我运行这段代码时:if $row["count"] > 0 else块运行和 $_SESSION["error"]设置。 当$row["coun
我有一个关于 php $_SESSION 的问题。 假设我有一个用户 A 输入index.php,它输入了一些信息, $_SESSION['info'] = userA 现在用户B输入index.ph
我目前正在使用 onclick() 处理一张 table 将信息发送到 PHP 页面的元素。 基本思想是,如果单击一门类(class)(例如法语、数学、英语等),PHP 页面会检索该值,然后执行 SQ
我有条件地在给定页面上嵌入两个标题之一:“公司”或“学生和专业人士”。 我在登录时将用户类型(“”、“学生”或“专业”)存储在 $_SESSION 数组中,然后使用简单的 if 语句来确定要嵌入哪个
示例我有 100 个表单字段。每个字段都会有错误 session 。成功提交表单后,我想取消设置任何以 $_SESSION['submit_'] 开头的 session 首先我可以这样做 unset(
我正在处理一个项目,但 $_SESSION['username'] 没有回应 我使用了 var_dump,这就是我从该结果中得到的结果 我的问题是如何修复. array(4) { ["SES
我有条件地在给定页面上嵌入两个标题之一:“公司”或“学生和专业人士”。 我在登录时将用户类型(“”、“学生”或“专业”)存储在 $_SESSION 数组中,然后使用一个简单的 if 语句来确定要嵌入哪
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我正在为一家小公司开发一款供内部使用的简单应用。我很难让帐户登录正常工作,我相信这与 $_SESSION 没有像我预期的那样设置有关。现在我对 PHP 还很陌生,并且一直在学习。 index.php
我最近正在尝试解决一些关于 Session 的问题,现在我需要帮助才能使用 XAMPP 获得一个小页面。 我使用 4 个页面进行测试: 1) index.php是用户填写ID和PW的页面。 2) lo
我有两个单独的页面,一个页面是上传文件的地方,另一个页面显示信息。 在 imageupload.php 页面中,我在下面有这个 session : $_SESSION['fileImage']['na
我正在尝试更新数据库中的表。这是我到目前为止的代码: $query = "UPDATE user SET name='$name', pword='$pword', email='$email', a
我是一名优秀的程序员,十分优秀!