我想为管理员和用户角色显示不同的菜单链接,以下是我目前拥有的菜单链接,但是以admin身份登录时它显示了用户仪表板和课程,以用户身份登录时它显示了所有相同的菜单链接,有人帮助您进行编码,并对其进行快速浏览,以免不确定如何找到最佳的编码方式?预先谢谢你
<nav class="sidebar-nav">
<ul id="sidebarnav">
<?php if(isset($_SESSION['admin']) && $_SESSION['role']=='admin'); {
echo '
<li><a href="admin-dashboard.php" aria-expanded="false"><i class="fa fa-tachometer"></i><span class="hide-menu">Admin Dashboard</span></a></li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-map-marker"></i><span class="hide-menu">Horses</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="add-edit-horse.php"><i class="fa fa-plus"></i> New Horse</a></li>
<li><a href="view-all-horses.php"><i class="fa fa-search"></i> View Horses</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-users"></i><span class="hide-menu">Riders</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="add-edit-rider.php"><i class="fa fa-user-plus"></i> New Rider</a></li>
<li><a href="view-all-riders.php"><i class="fa fa-users"></i> View Riders</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-users"></i><span class="hide-menu">Instructors</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="add-edit-instructor.php"><i class="fa fa-user-plus"></i> New Instructor</a></li>
<li><a href="view-all-instructors.php"><i class="fa fa-users"></i> View Instructors</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-users"></i><span class="hide-menu">Grooms</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="add-edit-groom.php"><i class="fa fa-user-plus"></i> New Groom</a></li>
<li><a href="view-all-grooms.php"><i class="fa fa-users"></i> View Grooms</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-calendar"></i><span class="hide-menu">Lessons</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="view-lessons-calendar.php"><i class="fa fa-calendar"></i> View Lessons Calendar</a></li>
<li><a href="view-all-lessons.php"><i class="fa fa-calendar"></i> View Lessons</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-users"></i><span class="hide-menu">Users</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="view-all-users.php"><i class="fa fa-users"></i> View Users</a></li>
</ul>
</li>
<li><a href="logout.php"><i class="fa fa-sign-out"></i><span class="hide-menu">Logout</span></a></li>
';
}
if(isset($_SESSION['user']) && $_SESSION['role']=='user'); {
echo '
<li><a href="user-dashboard.php" aria-expanded="false"><i class="fa fa-tachometer"></i><span class="hide-menu">User Dashboard</span></a></li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-calendar"></i><span class="hide-menu">Lessons</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="view-lessons-calendar.php"><i class="fa fa-calendar"></i> View Lessons Calendar</a></li>
<li><a href="view-all-lessons.php"><i class="fa fa-calendar"></i> View Lessons</a></li>
</ul>
</li>';
}
?>
</ul>
</nav>
答案 0 :(得分:0)
您可以那样做。
<?php
require_once('phpmailer/PHPMailerAutoload.php');
$toemails = array();
$toemails[] = array(
'email' => 'test@test.com', // Your Email Address
'name' => 'Some type of name' // Your Name
);
// Form Processing Messages
$message_success = 'We have <strong>successfully</strong> received your Message and will get Back to you as soon as possible.';
// Add this only if you use reCaptcha with your Contact Forms
$recaptcha_secret = 'your-recaptcha-secret-key'; // Your reCaptcha Secret
$mail = new PHPMailer();
// If you intend you use SMTP, add your SMTP Code after this Line
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['template-contactform-email'] != '') {
$name = isset($_POST['template-contactform-name']) ? $_POST['template-contactform-name'] : '';
$email = isset($_POST['template-contactform-email']) ? $_POST['template-contactform-email'] : '';
$phone = isset($_POST['template-contactform-phone']) ? $_POST['template-contactform-phone'] : '';
$subject = isset($_POST['template-contactform-subject']) ? $_POST['template-contactform-subject'] : '';
$subject = isset($subject) ? $subject : 'Ladies Boxing Offer';
$botcheck = $_POST['template-contactform-botcheck'];
if ($botcheck == '') {
$mail->SetFrom($email, $name);
$mail->AddReplyTo($email, $name);
foreach ($toemails as $toemail) {
$mail->AddAddress($toemail['email'], $toemail['name']);
}
$mail->Subject = $subject;
$name = isset($name) ? "Name: $name<br><br>" : '';
$email = isset($email) ? "Email: $email<br><br>" : '';
$phone = isset($phone) ? "Phone: $phone<br><br>" : '';
$referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Enquiry was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';
$body = "$name $email $phone $service $message $referrer";
// Runs only when File Field is present in the Contact Form
if (isset($_FILES['template-contactform-file']) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK) {
$mail->IsHTML(true);
$mail->AddAttachment($_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name']);
}
// Runs only when reCaptcha is present in the Contact Form
if (isset($_POST['g-recaptcha-response'])) {
$recaptcha_response = $_POST['g-recaptcha-response'];
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response);
$g_response = json_decode($response);
if ($g_response->success !== true) {
echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }';
die;
}
}
$mail->MsgHTML($body);
$sendEmail = $mail->Send();
if ($sendEmail == true):
echo '{ "alert": "success", "message": "' . $message_success . '" }';
else:
echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '" }';
endif;
} else {
echo '{ "alert": "error", "message": "Bot <strong>Detected</strong>.! Clean yourself Botster.!" }';
}
} else {
echo '{ "alert": "error", "message": "Please <strong>Fill up</strong> all the Fields and Try Again." }';
}
} else {
echo '{ "alert": "error", "message": "An <strong>unexpected error</strong> occured. Please Try Again later." }';
}
?>
请记住,在文件开头必须具有以下内容:
<nav class="sidebar-nav">
<ul id="sidebarnav">
<?php if(isset($_SESSION['admin']) && $_SESSION['role'] == 'admin') { ?>
<li><a href="admin-dashboard.php" aria-expanded="false"><i class="fa fa-tachometer"></i><span class="hide-menu">Admin Dashboard</span></a></li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-map-marker"></i><span class="hide-menu">Horses</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="add-edit-horse.php"><i class="fa fa-plus"></i> New Horse</a></li>
<li><a href="view-all-horses.php"><i class="fa fa-search"></i> View Horses</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-users"></i><span class="hide-menu">Riders</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="add-edit-rider.php"><i class="fa fa-user-plus"></i> New Rider</a></li>
<li><a href="view-all-riders.php"><i class="fa fa-users"></i> View Riders</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-users"></i><span class="hide-menu">Instructors</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="add-edit-instructor.php"><i class="fa fa-user-plus"></i> New Instructor</a></li>
<li><a href="view-all-instructors.php"><i class="fa fa-users"></i> View Instructors</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-users"></i><span class="hide-menu">Grooms</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="add-edit-groom.php"><i class="fa fa-user-plus"></i> New Groom</a></li>
<li><a href="view-all-grooms.php"><i class="fa fa-users"></i> View Grooms</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-calendar"></i><span class="hide-menu">Lessons</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="view-lessons-calendar.php"><i class="fa fa-calendar"></i> View Lessons Calendar</a></li>
<li><a href="view-all-lessons.php"><i class="fa fa-calendar"></i> View Lessons</a></li>
</ul>
</li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-users"></i><span class="hide-menu">Users</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="view-all-users.php"><i class="fa fa-users"></i> View Users</a></li>
</ul>
</li>
<li><a href="logout.php"><i class="fa fa-sign-out"></i><span class="hide-menu">Logout</span></a></li>
<?php } ?>
<?php if(isset($_SESSION['user']) && $_SESSION['role'] == 'user') { ?>
<li><a href="user-dashboard.php" aria-expanded="false"><i class="fa fa-tachometer"></i><span class="hide-menu">User Dashboard</span></a></li>
<li> <a class="has-arrow" href="#" aria-expanded="false"><i class="fa fa-calendar"></i><span class="hide-menu">Lessons</span></a>
<ul aria-expanded="false" class="collapse">
<li><a href="view-lessons-calendar.php"><i class="fa fa-calendar"></i> View Lessons Calendar</a></li>
<li><a href="view-all-lessons.php"><i class="fa fa-calendar"></i> View Lessons</a></li>
</ul>
</li>
<?php } ?>
</ul>
</nav>