比如我的主页网址为inden,子页为inden_zy,我在浏览器中输入子页网址时,必须先跳转到主页的index网址
该怎样写

解决方案 »

  1.   


    if()//判断没有登录
    {
      header("Location: index.php\n");
      exit;
    }
      

  2.   

    index中在SESSION中设定一个标志位
    $_SESSION['FORMINDEX'] = "yes";然后在index_zy中判断
    session_start();
    if(!isset($_SESSION['FORMINDEX'])){
       header("location: index.php");
    }
      

  3.   

    写后报错Cannot send session cache limiter - headers already sent (output started at D:\APMServ5.2.6\www\htdocs\hotel_index\lianjie.php:8)什么意思
      

  4.   

    header之前不能有输出。
    echo,print_r,HTML页面输出都不可以有。
      

  5.   

    还是不行啊,
    这是主页代码<?php
    session_start();
    include("lianjie.php");
    ?>
    <?php
    $_SESSION['FORMINDEX'] = "yes";
    ?>
    <script type="text/javascript">
    function Checkform()
    {    if(document.form1.user_login.value=="")
    {
      alert("用户名不能为空");
      document.form1.user_login.focus();
      return false;
    }
    else if(document.form1.user_pass.value == "")
    {
      alert("密码不能为空");
      document.form1.user_pass.focus();
      return false;
    }
    else
    {
      return true;
    }
    }
    </script>
    <!--***************登录页面***************-->
    <link href="CSS/css.css" rel="stylesheet" type="text/css">
    <body >
    <table width="800px"align="center"  >
    <tr>
    <td align="right" valign="top"><img src="img/logo01.jpg" align="right"></td>
    </tr>
    <tr><td height="252" colspan="3">
      <form name="form1" method="post" action="" onsubmit="return Checkform();"  style=" text-align:center; ">
            <table width="100%" height="300"  style="background-image:url(img/background.jpg);">
              <tr>
                <td align="center" colspan="2">
                  <table border="0" cellspacing="0" cellpadding="1" align="center">
        <tr>
                <td colspan="2" align="center" height="50px"><font color="#FFFFFF" face="华文宋体" size="+1">用户登录</font></td>
                  </tr>
        <tr>
                      <td height="30">
                      <div align="right" style="color:#FFFFFF; font-size:13px; height:10px;">用户名:</div></td>
                      <td align="left">
                        <input type="text" name="user_login" size="20" maxlength="16"  style="border-color:#666666;">
                      </td>
                    </tr>
                    <tr><td height="30">
                        <div align="right" style="color:#FFFFFF;font-size:13px;height:30px;">密&nbsp;码:</div></td>
                      <td align="left">
                        <input type="password" name="user_pass" size="20" maxlength="16" style="border-color:#666666;"><p>
                      </td>
                    </tr>
                     
                    <tr>
    <td colspan="2">
                        <div align="center">
                          <input type="image" name="login" value=""  src="img/hotel_dl.jpg">
                      </div></td>
                    </tr>
                </table></td>
              </tr>
            </table>
      </form>
      </td>
    </tr>
    </table>
    </body>
    <?php
    $user_login=$_POST["user_login"];//赋值
    $user_pass=$_POST["user_pass"];
    if($user_login && $user_pass)
    {
        $query="select * from background where user='".$user_login."' and pwd='".$user_pass."'";//从数据库查找用户名和密码
        $res=mysql_query($query,$connection);
           if(mysql_fetch_array($res))
           {
           $_SESSION['user_login']=$user_login;//传递用户名
            echo $SESSION['user_login'];
            echo "<script>window.location='index_bc.htm';</script>";exit();//登录成功跳转到index_bc
           }else{
               echo "<script>alert('用户名或密码错误');window.location='index.php';</script>";exit();
    }
    }
    这是子页
    <?php
    include("lianjie.php");
    ?>
    <link href="CSS/css.css" rel="stylesheet" type="text/css">
    <script> 
    function   delconfirm(){ 
        if(window.confirm( "请确认是否删除? ")){ 
          return true; 
        } 
        return false; 

    </script> <form method="POST" action="">
    <fieldset style="width:600px;">
    <legend>酒店活动数据查询</legend>
    <p>
    <table  width="600">
      <tr>
         <td align=left>搜&nbsp;索&nbsp;条&nbsp;件&nbsp;:<select name="ziduan" style="width:155px;">
    <option value="select=select">查看全部数据</option>
    <option value="hotel_id">酒店ID</option>
    <option value="content">内容介绍</option>
    <option value="source">备注</option>
    <option value="s_type">s_type</option>
         </td>
          <td align=left>搜索关键字:<input name="txt_sousuo" type="text" value=""/>
      </td>
      <td align="left">
      <input name="sousuo" type="image" value="" src="img/03.gif" />
      </td>
      </tr>
    </table>
    </fieldset>
    </form>
    <p>
    <?php

    。。?>
    <?php
    echo "</div>";
    echo "</table>";
    echo "<div align='center' class='shu'>"."共".$maxPage."页&nbsp;&nbsp;&nbsp;&nbsp;当前为第".$page."页"."</div>";
    mysql_close($connection); //关闭与数据库的连接 */
    ?>
    <?php
    session_start();
    if(!isset($_SESSION['FORMINDEX'])){
      header("location:index.php");
    }
    ?>
      

  6.   

    子页代码中把
    <?php
    session_start();
    if(!isset($_SESSION['FORMINDEX'])){
      header("location:index.php");
    }
    放到最前面去。
      

  7.   

    我这个进入登陆系统后是个框架页http://127.0.0.1/hotel_index/index_kj.htm
    框架页连接着各个PHP页,这怎么写
      

  8.   

    我这个进入登陆系统后是个框架页http://127.0.0.1/hotel_index/index_kj.htm框架页连接着各个PHP页,这怎么写