停止直接访问 .html 页面,重定向到 login.php [英] Stop direct access to .html pages without , redirect to login.php

查看:75
本文介绍了停止直接访问 .html 页面,重定向到 login.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个答案,以便检查根目录(或外部)中的所有其他 .html 页面是否已发生会话.如果不是直接访问者返回 index.php(登录所在的位置,在 public_html 中设置).有没有人解决这个问题?如果是这样,我会将如果没有会话重定向"放在哪里?因此,如果有人直接访问 www.site.com/here.html,则 php 会运行并查看会话是否已启动,如果没有则重定向到 www.site.com/login.php.

解决方案

好的亚历克斯,这就是我想出来的,但还没有运行它.只是在寻找我是否接近.我当然不是,这是我第一次向网站添加此类功能.

('text'=>'Help', 'Help.html'=>'?p=Help'),'注销' =>('text'=>'注销', 'logout.php'=>'?p=Logout'),);$menu2 = 数组(营销部"=>('text'=>'市场部', 'Welcome.html'=>'?p=home'),'打印'=>('文本'=>'打印', 'Printing.html'=>'?p=打印'),'电子邮件营销' =>('text'=>'电子邮件营销', 'Emailing.html'=>'?p=Emailing'),'网站开发' =>('text'=>'网站开发', 'Website.html'=>'?p=Website'),'Marketing-Projects' =>('text'=>'Marketing-Projects', 'Marketing-Projects.html'='?'?p=Marketing-Projects'),'MarketingSchedules' =>('text'=>'MarketingSchedules', 'MarketingSchedules.html'),'MarketingDepartmentSchedules' =>('text'=>"Marketing Department Schedules, MarketingDepartmentSchedules.html"),'Help' =>('text'=>'Help', 'Help.html'=>'?p=Help'),'注销' =>('text'=>'注销', 'logout.php'=>'?p=Logout'),);$menu3 = 数组(营销部"=>('text'=>'市场部', 'Welcome.html'=>'?p=home'),'打印'=>('文本'=>'打印', 'Printing.html'=>'?p=打印'),'电子邮件营销' =>('text'=>'电子邮件营销', 'Emailing.html'=>'?p=Emailing'),'网站开发' =>('text'=>'网站开发', 'Website.html'=>'?p=Website'),'Marketing-Projects' =>('text'=>'Marketing-Projects', 'Marketing-Projects.html'='?'?p=Marketing-Projects'),'MarketingSchedules' =>('text'=>'MarketingSchedules', 'MarketingSchedules.html'),'MarketingDepartmentSchedules' =>('text'=>"Marketing Department Schedules, MarketingDepartmentSchedules.html"),'MarketingExpenseReports' =>('text'=>"营销费用报告", 'MarketingExpenseReports.php'),'Help' =>('text'=>'Help', 'Help.html'=>'?p=Help'),'注销' =>('text'=>'注销', 'logout.php'=>'?p=Logout'),);$menuAdmin = 数组(营销部"=>('text'=>'市场部', 'Welcome.html'=>'?p=home'),'打印'=>('文本'=>'打印', 'Printing.html'=>'?p=打印'),'电子邮件营销' =>('text'=>'电子邮件营销', 'Emailing.html'=>'?p=Emailing'),'网站开发' =>('text'=>'网站开发', 'Website.html'=>'?p=Website'),'Marketing-Projects' =>('text'=>'Marketing-Projects', 'Marketing-Projects.html'='?'?p=Marketing-Projects'),'MarketingSchedules' =>('text'=>'MarketingSchedules', 'MarketingSchedules.html'),'MarketingDepartmentSchedules' =>('text'=>"Marketing Department Schedules, MarketingDepartmentSchedules.html"),'MarketingExpenseReports' =>('text'=>"营销费用报告", 'MarketingExpenseReports.php'),'Help' =>('text'=>'Help', 'Help.html'=>'?p=Help'),'注销' =>('text'=>'注销', 'logout.php'=>'?p=Logout'),);}功能 aprovedusers($aprovedusers){//为销售部门设置批准用户列表 1$aprovedusers1=array("user1");//设置批准用户列表 2$aprovedusers2=array("user1","user2");//为市场部设置批准用户列表3$aprovedusers3=array("user1","user2","user3");//为管理员设置批准的用户列表管理员$aprovedusersAdmin=array("Admin1");$msg1 = echo "你好";$msg2 = echo "必须登录";$msg3 = echo "你好营销";$msg4 = echo "你好管理员";}函数 getloggedin($userloggedin){if($_SESSION['用户登录'] == ''){echo $msg1 '用户登录';} 别的 {header("位置:logout.php");}回声 $msg2;echo '<div id="'.$userlogin .'">';?><html lang="zh-cn"><头><meta charset="UTF-8"><title>营销主页</title><标题><div id="菜单"><div id="<?php echo $userloggedin ?>"><?php//仅显示批准的菜单,用于批准哪个菜单用户?><div id="<?php echo $menuOptions ?>"><div><?php echo $menu1?></div><div><?php echo $menu2?></div><div><?php echo $menu3?></div><div><?php echo $menuAdmin?></div>

<身体><div id="内容">

</标题>

如果你有任何很棒的指示,我会在学习过程中通宵学习!

I've been looking for an answer to make all my other .html pages in the root directory(or outside of) to be checked against if a session has taken place or not. If not direct visitor back to index.php (where login is, set in public_html). Does anyone have a work around for this? If so where would I put the "if no session redirect"? So if someone just goes directly to www.site.com/here.html the php runs and see's if the session had been instated, if not redirects to www.site.com/login.php.

解决方案

Ok Alex, this is what I came up with but haven't ran it yet. Just looking for if I'm even coming close. Surely I'm not, this is my first go at adding this type of functionality to a site.

<?php
    function menuOptions($menuOptions)
  {
    $menu1 = array(
        'Marketing Dept.' =>('text'=>'Marketing Dept.', 'Welcome.html'=>'?p=home'),
        'Printing' =>('text'=>'Printing', 'Printing.html'=>'?p=Printing'),
        'Email Marketing' =>('text'=>'Email Marketing', 'Emailing.html'=>'?p=Emailing'),
        'Website Development' =>('text'=>'Website Development', 'Website.html'=>'?p=Website'),
        'Help' =>('text'=>'Help', 'Help.html'=>'?p=Help'),
        'Logout' =>('text'=>'Logout', 'logout.php'=>'?p=Logout'),
    );
    $menu2 = array(
        'Marketing Dept.' =>('text'=>'Marketing Dept.', 'Welcome.html'=>'?p=home'),
        'Printing' =>('text'=>'Printing', 'Printing.html'=>'?p=Printing'),
        'Email Marketing' =>('text'=>'Email Marketing', 'Emailing.html'=>'?p=Emailing'),
        'Website Development' =>('text'=>'Website Development', 'Website.html'=>'?p=Website'),
        'Marketing-Projects' =>('text'=>'Marketing-Projects', 'Marketing-Projects.html'=>'?p=Marketing-Projects'),
        'MarketingSchedules' =>('text'=>'Marketing Department Schedules', 'MarketingSchedules.html'),   
        'MarketingDepartmentSchedules' =>('text'=>"Marketing Department Schedules, MarketingDepartmentSchedules.html"),
        'Help' =>('text'=>'Help', 'Help.html'=>'?p=Help'),
        'Logout' =>('text'=>'Logout', 'logout.php'=>'?p=Logout'),
    );
    $menu3 = array(
        'Marketing Dept.' =>('text'=>'Marketing Dept.', 'Welcome.html'=>'?p=home'),
        'Printing' =>('text'=>'Printing', 'Printing.html'=>'?p=Printing'),
        'Email Marketing' =>('text'=>'Email Marketing', 'Emailing.html'=>'?p=Emailing'),
        'Website Development' =>('text'=>'Website Development', 'Website.html'=>'?p=Website'),
        'Marketing-Projects' =>('text'=>'Marketing-Projects', 'Marketing-Projects.html'=>'?p=Marketing-Projects'),
        'MarketingSchedules' =>('text'=>'Marketing Department Schedules', 'MarketingSchedules.html'),   
        'MarketingDepartmentSchedules' =>('text'=>"Marketing Department Schedules, MarketingDepartmentSchedules.html"),
        'MarketingExpenseReports' =>('text'=>"Marketing Expense Reports", 'MarketingExpenseReports.php'),
        'Help' =>('text'=>'Help', 'Help.html'=>'?p=Help'),
        'Logout' =>('text'=>'Logout', 'logout.php'=>'?p=Logout'),
    );
    $menuAdmin = array(
        'Marketing Dept.' =>('text'=>'Marketing Dept.', 'Welcome.html'=>'?p=home'),
        'Printing' =>('text'=>'Printing', 'Printing.html'=>'?p=Printing'),
        'Email Marketing' =>('text'=>'Email Marketing', 'Emailing.html'=>'?p=Emailing'),
        'Website Development' =>('text'=>'Website Development', 'Website.html'=>'?p=Website'),
        'Marketing-Projects' =>('text'=>'Marketing-Projects', 'Marketing-Projects.html'=>'?p=Marketing-Projects'),
        'MarketingSchedules' =>('text'=>'Marketing Department Schedules', 'MarketingSchedules.html'),   
        'MarketingDepartmentSchedules' =>('text'=>"Marketing Department Schedules, MarketingDepartmentSchedules.html"),
        'MarketingExpenseReports' =>('text'=>"Marketing Expense Reports", 'MarketingExpenseReports.php'),
        'Help' =>('text'=>'Help', 'Help.html'=>'?p=Help'),
        'Logout' =>('text'=>'Logout', 'logout.php'=>'?p=Logout'),
    );
}


    function aprovedusers($aprovedusers)
{
    // setting aproved users list 1 for sales department
    $aprovedusers1=array("user1");

    // setting aproved users list 2
    $aprovedusers2=array("user1","user2");

    // setting aproved users list 3 for marketing department
    $aprovedusers3=array("user1","user2","user3");

    // setting aproved users list admin for admin
    $aprovedusersAdmin=array("Admin1");

    $msg1 = echo "hello";
    $msg2 = echo "must login";
    $msg3 = echo "hello Marketing";
    $msg4 = echo "hello Admin";

}

function getloggedin($userloggedin)
{
    if($_SESSION['userlogin'] == ''){
    echo $msg1 'userlogin';
    } else {
    header("Location: logout.php");
}
echo $msg2;




  echo '<div id="'. $userlogin .'">';

 ?>
 <html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Markting Home</title>
 </head>
 <header>
   <div id="Menu">
    <div id="<?php echo $userloggedin ?>" >
        <?php //show only approved menu for what menu user is approved for ?>
        <div id="<?php echo $menuOptions ?>" >
            <div><?php echo $menu1?></div>
            <div><?php echo $menu2?></div>
            <div><?php echo $menu3?></div>
            <div><?php echo $menuAdmin?></div>
        </div>
    </div>
   </div>
     <body>
       <div id="content">
     </div>
   </body>
  </header>

I'll be working on it all night learning as I go if you have any pointers that would great!

这篇关于停止直接访问 .html 页面,重定向到 login.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆