【发布时间】:2014-01-26 08:47:48
【问题描述】:
好的,我有一个名为 profile.php 的脚本,我希望用户从不同的 html 页面或 php 脚本(如 user_settings.php)与 profile.php“表单输入”进行交互。
我希望仅将 profile.php 中的错误显示/回显/打印在 user_settings.php 页面上。我已经尝试了以下
----profile.php---
<?php ob_start(); require_once ("core/init.php"); ?>
<?php require ("includes/overall/header.php"); ?>
<?php
if(has_access($session_user_id, 1) === true){
$message[] = '<p class="admin"> **Admin**</p>';
}
?>
<div id="mainInfo">
<p class="profile"> Hello <?php echo $user_data['first_name'], '!' .output_message($message) ;?> </p><br /><br />
<?php
if(isset($_FILES['image']) === true)
{
if(empty($_FILES['image']['name']) === true)
{
$errors_image[] = 'Please choose a file';
}
else
{
$allowed = array('jpg', 'jpeg', 'gif', 'png');
$file_name = $_FILES['image']['name'];
$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['image']['tmp_name'];
if(in_array($file_extn, $allowed) === true)
{
change_profile_image($session_user_id, $file_temp, $file_extn);
header('Location: profile');
exit();
}
else
{
$errors_image[] = 'Incorrect file type. Allow: ';
echo implode(', ', $allowed);
}
}
}
if(empty($user_data['image']) === false)
{
echo '<p class="photo"><image src="', $user_data['image'],'" alt="', $user_data['first_name'], '\'s Profile Image"></p> <br>';
}
?>
<p class="usr_sttngs"> <a href="usr_sttngs">Update Info!</a></p><br />
</div>
<?php require ("includes/overall/footer.php"); ?>
--------usr_sttngs.php------------
<?php ob_start();
require_once ("core/init.php");
ini_set('display_errors', 'On'); error_reporting(E_ALL);
protect_page(); ?>
<?php
if(empty($_POST) === false)
{
$required_fields = array('current_passwd','passwd', 'passwd_again');
foreach($_POST as $key => $value)
{
if (empty($value) && in_array($key, $required_fields) === true)
{
$errors[] = '<p class="postad_msg">Fields marked with * are required.</p>';
break 1;
}
}
if (sha1($_POST['current_passwd']) === $user_data['passwd'])
{
if(trim($_POST['passwd']) !== trim($_POST['passwd_again']))
{
$errors[] = '<p class="postad_msg">New passwords DO NOT match!</p>';
}
else if (strlen($_POST['passwd']) < 6)
{
$errors[] = '<p class="postad_msg">New passwords must be at least 6 characters.</p>';
}
}
else
{
$errors[] = '<p class="postad_msg">Your current password is incorrect!</p>';
}
}
?>
<?php require ("includes/overall/header.php"); ?>
<div id="mainInfo">
<br /> <br /><p3>Change Password!</p3> <br /> <br />
<?php
if(isset($_GET['success']) && empty($_GET['success']))
{
$message[] = '<p class="postad_msg">Your password has been changed successfully.</p>';
}
if(empty($_POST) === false && empty($errors) === true)
{
change_passwd($session_user_id, $_POST['passwd'] );
//redirect
header('Location: usr_sttngs?success');
//exit
exit();
}
else if(empty($errors) === false)
{
output_errors($errors);
}
?>
<form method="post" action="usr_sttngs">
<fieldset>
<label for="currentpasswd">Current password* </label>
<input placeholder="Type your current password" type="password" name="current_passwd" size="30" maxlength="50" value="<?php echo htmlentities($current_passwd); ?>" /><br /><br />
<label for="last_name">New Password* </label>
<input placeholder="New Password" type="password" name="passwd" size="30" maxlength="50" value="<?php echo htmlentities($new_passwd); ?>" /><br /><br />
<label for="email">New Password Again* </label>
<input placeholder="Retype New Password" type="password" name="passwd_again" size="30" maxlength="50" value="<?php echo htmlentities($new_passwd_again); ?>" />
</fieldset>
<fieldset class="center">
<input class="submit" type="submit" name="submit" value="Change Password" />
<?php echo output_errors($errors); ?>
<?php echo output_message($message);?>
</fieldset>
</form>
<p4>Change profile photo!</p4> <br /> <br />
<form action="profile" method="post" enctype="multipart/form-data">
<fieldset class="center">
<input type="file" name="image"> <input type="submit">
<?php echo output_errors($errors_image);
require_once ('$_SERVER["DOCUMENT_ROOT"]\profile.php');
?>
</fieldset>
</form>
<br /><br /><br /><p4>Upload your resume!</p4> <br />
<form action="profile" method="post" enctype="multipart/form-data">
<fieldset class="center">
<input type="file" name="resume"> <input type="submit">
</fieldset>
</form>
</div>
<?php require ("includes/overall/footer.php"); ?>
我尝试了我在以下帖子Want to echo a php variable from another page 上阅读的内容,但没有得到想要的结果。所以我尝试包含 required_once 'profile.php' ;在 user_setting.php 文件的最顶部,这只是给了我一个空白页。任何帮助将不胜感激。谢谢!
【问题讨论】:
-
您说您得到一个空白页面,这可能是由 PHP 错误引起的,您的服务器可能配置为不显示它们。将这两行放在文件顶部,如果有任何更改,请发布:
ini_set('display_errors', 'On'); error_reporting(E_ALL);(来自here) -
嗨 user1781026 这是我得到的错误 -------警告:require_once(profile):无法打开流:C:\dir\subdir\user_settings 中没有这样的文件或目录。 php on line 97 致命错误:require_once(): Failed opening required 'profile' (include_path='.;C:\php\pear') in C:\dir\subdir\usr_sttngs.php on line 97----
-
试试这个:
require_once('profile.php')。确保 profile.php 和 user_setting.php 都在同一个目录中,如果不使用类似require_once('directory/profile.php') -
它们都在根目录中,我什至尝试了以下 require_one('$_SERVER[DOCUMENT_ROOT]/profile.php');无济于事:(
-
这可能是由几件事引起的:您写了
_one而不是_once,而变量在单引号'like this'中的工作方式不一样。您还必须将 DOCUMENT_ROOT 放在引号中。更正:require_once($_SERVER["DOCUMENT_ROOT"].'profile.php');