使用 php 中另一页表格中的信息填充证书
Populate a certificate with information from a form on another page in php
我正在创建用户将参加测验的电子学习。提交后,他们将被发送到结果页面,在那里将显示他们的分数。如果用户通过 link 将弹出一个证书,他们可以打印出来。我无法获得证书来填充变量(名字、姓氏等)。
这是我拥有的:
index.php(他们参加测验和填写表格的主页)
<form id="form1" name="form1" method="post" action="results.php" onsubmit="return validateForm() ;">
<label>Last Name:
<input type="text" name="lname" id="lname" tabindex="1" />
</label>
<label>First Name:
<input type="text" name="fname" id="fname" tabindex="2" />
</label>
<label>Title:
<input type="text" name="title" id="title" tabindex="3" /><br/><br/>
</label>
<?php
$quiz = new Quiz( $questions );
echo $quiz->renderQuiz();
?>
<input name="Submit" type="submit" value="Submit" />
</form>
在 results.php 上(显示结果和 link 证书的页面)
<?php
$ip = $_SERVER['REMOTE_ADDR']; // employee's Ip address
$time = date("d/m/y : H:i:s", time()); // current timestamp
$email_string = create_email_string( $force_email, $_POST['email_to'] );
$questions_correct = array();
$info_to_save = array( $_POST['lname'], $_POST['fname'], $_POST['title'];
// Grades the quiz
$score = (string)round( ( count($questions_correct) / count($questions)*100), 2 );
$variables = array();
$variables['fname'] = $_POST['fname'];
$variables['lname'] = $_POST['lname'];
$variables['test_name'] = $test_name;
$variables['score'] = $score;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Results</title>
<link rel="stylesheet" type="text/css" href="./stylesheets/quiz_stylesheet.css" />
</head>
<body>
<div id="white">
<div id="header">
<img src="./images/ucdheader.jpg" width="1000" id="header" /img>
</div>
<div id="mainContent">
<h1><span>You Scored <?php echo $score ?>%</span>
<br><?php if ($score >= 80)
echo "<a href=certificate.php >Print Certificate</a>
"?></h1>
<p>Below are your results for <?php echo $test_name; ?>. In order to pass this quiz, you must score 80% or better. If you would like to try again, click the following link.</p>
<a href='<?php echo $test_page_name ?>'>Try again</a>
<p>These results were sent to the following addresses: </p>
<ul>
<?php
$all_emailed_to = explode( "; " , $email_string);
foreach ($all_emailed_to as $email) {
echo "<li>" . $email . "</li>";
}
?>
</ul>
</div>
</div>
</body>
</html>
在 certificate.php
<title>Certificate</title>
</head>
<body>
<div id="white">
<div class="btn-group btn-group-lg">
<a role="button" class="btn btn-default" href="#" data- function="print">Print Certificate</a>
</div>
<div class="certificate">
<img src="images/cert.png" width="820" height="527" id="cert" />
<div class="name">
<?php $variables['fname'] . " " . $variables['lname'] . ?>
</div>
<div class="course">
<p></p>
</div>
<div class="completion_date">
<?php $variables['time']; ?>
</div>
</div>
</div>
</body>
</html>
谢谢!
要么采用 Kamran 的方法并构建一个隐藏表单,该表单将通过 POST 发送证书页面中所需的信息,要么采用面向数据库的模型(即保存用户及其结果,然后检索这些信息以生成证书)。
第一种方法非常不安全,因为您可以使用 Firebug 更改字段的值,如果您不测试这些值,则发送脏的意外输入。
您没有向 certificate.php 页面传递任何变量。在 php 页面之间传递数据有多种选择,例如:
1)会议
2) $_POST
3) $_GET
代码中的 easiest 选项正在使用 $_GET 变量。只需在 results.php:
中使用这行代码
echo "<a href=certificate.php?fname={$variables['fname']}&lname={$variables['lname']} >Print Certificate</a>"?></h1>
比 certificate.php 使用以下方法检索数据:
<?php echo $_GET['fname'] . " " . $_GET['lname'] . ?>
注意 1:您将需要 urlendode()
link 中的变量,以防有人在他们的 name/last 名称中放置特殊的椅子
注 2:这是一种可破解的方法。员工可以通过调用准备好的 url.
打印带有任何 name/last 名称的证书
最好的方法是重写所有三个页面以使用会话:http://php.net/manual/en/features.sessions.php
In results.php 在 SESSION 中存储必要的值:
$info_to_save = array( $_POST['lname'], $_POST['fname'], $_POST['title'], time);
//Start session if not started
if (!isset($_SESSION)) {
session_start();
}
$_SESSION['certInfo'] = $info_to_save;
然后像这样在 certificate.php 中使用它:
//Start session if not started
if (!isset($_SESSION)) {
session_start();
}
$lname = $_SESSION['certInfo'][0];
$fname = $_SESSION['certInfo'][1];
$title = $_SESSION['certInfo'][2];
$time = $_SESSION['certInfo'][3];
我正在创建用户将参加测验的电子学习。提交后,他们将被发送到结果页面,在那里将显示他们的分数。如果用户通过 link 将弹出一个证书,他们可以打印出来。我无法获得证书来填充变量(名字、姓氏等)。 这是我拥有的:
index.php(他们参加测验和填写表格的主页)
<form id="form1" name="form1" method="post" action="results.php" onsubmit="return validateForm() ;">
<label>Last Name:
<input type="text" name="lname" id="lname" tabindex="1" />
</label>
<label>First Name:
<input type="text" name="fname" id="fname" tabindex="2" />
</label>
<label>Title:
<input type="text" name="title" id="title" tabindex="3" /><br/><br/>
</label>
<?php
$quiz = new Quiz( $questions );
echo $quiz->renderQuiz();
?>
<input name="Submit" type="submit" value="Submit" />
</form>
在 results.php 上(显示结果和 link 证书的页面)
<?php
$ip = $_SERVER['REMOTE_ADDR']; // employee's Ip address
$time = date("d/m/y : H:i:s", time()); // current timestamp
$email_string = create_email_string( $force_email, $_POST['email_to'] );
$questions_correct = array();
$info_to_save = array( $_POST['lname'], $_POST['fname'], $_POST['title'];
// Grades the quiz
$score = (string)round( ( count($questions_correct) / count($questions)*100), 2 );
$variables = array();
$variables['fname'] = $_POST['fname'];
$variables['lname'] = $_POST['lname'];
$variables['test_name'] = $test_name;
$variables['score'] = $score;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Results</title>
<link rel="stylesheet" type="text/css" href="./stylesheets/quiz_stylesheet.css" />
</head>
<body>
<div id="white">
<div id="header">
<img src="./images/ucdheader.jpg" width="1000" id="header" /img>
</div>
<div id="mainContent">
<h1><span>You Scored <?php echo $score ?>%</span>
<br><?php if ($score >= 80)
echo "<a href=certificate.php >Print Certificate</a>
"?></h1>
<p>Below are your results for <?php echo $test_name; ?>. In order to pass this quiz, you must score 80% or better. If you would like to try again, click the following link.</p>
<a href='<?php echo $test_page_name ?>'>Try again</a>
<p>These results were sent to the following addresses: </p>
<ul>
<?php
$all_emailed_to = explode( "; " , $email_string);
foreach ($all_emailed_to as $email) {
echo "<li>" . $email . "</li>";
}
?>
</ul>
</div>
</div>
</body>
</html>
在 certificate.php
<title>Certificate</title>
</head>
<body>
<div id="white">
<div class="btn-group btn-group-lg">
<a role="button" class="btn btn-default" href="#" data- function="print">Print Certificate</a>
</div>
<div class="certificate">
<img src="images/cert.png" width="820" height="527" id="cert" />
<div class="name">
<?php $variables['fname'] . " " . $variables['lname'] . ?>
</div>
<div class="course">
<p></p>
</div>
<div class="completion_date">
<?php $variables['time']; ?>
</div>
</div>
</div>
</body>
</html>
谢谢!
要么采用 Kamran 的方法并构建一个隐藏表单,该表单将通过 POST 发送证书页面中所需的信息,要么采用面向数据库的模型(即保存用户及其结果,然后检索这些信息以生成证书)。
第一种方法非常不安全,因为您可以使用 Firebug 更改字段的值,如果您不测试这些值,则发送脏的意外输入。
您没有向 certificate.php 页面传递任何变量。在 php 页面之间传递数据有多种选择,例如: 1)会议 2) $_POST 3) $_GET
代码中的 easiest 选项正在使用 $_GET 变量。只需在 results.php:
中使用这行代码echo "<a href=certificate.php?fname={$variables['fname']}&lname={$variables['lname']} >Print Certificate</a>"?></h1>
比 certificate.php 使用以下方法检索数据:
<?php echo $_GET['fname'] . " " . $_GET['lname'] . ?>
注意 1:您将需要 urlendode()
link 中的变量,以防有人在他们的 name/last 名称中放置特殊的椅子
注 2:这是一种可破解的方法。员工可以通过调用准备好的 url.
最好的方法是重写所有三个页面以使用会话:http://php.net/manual/en/features.sessions.php
In results.php 在 SESSION 中存储必要的值:
$info_to_save = array( $_POST['lname'], $_POST['fname'], $_POST['title'], time);
//Start session if not started
if (!isset($_SESSION)) {
session_start();
}
$_SESSION['certInfo'] = $info_to_save;
然后像这样在 certificate.php 中使用它:
//Start session if not started
if (!isset($_SESSION)) {
session_start();
}
$lname = $_SESSION['certInfo'][0];
$fname = $_SESSION['certInfo'][1];
$title = $_SESSION['certInfo'][2];
$time = $_SESSION['certInfo'][3];