dongmi0760 2013-06-27 14:09
浏览 45

PHP包含页面内容不刷新

i have a serious problem over here. I created a user system with sessions. The problem is that there is content you only see when you are logged in. For example in the navigation bar the sign in button is replaced with a account button.

Now to my problem: Every page php-includes the navbar.php. For example in the index.php is written:

<body>
<?php include("navbar.php")?>
</body>

The login.php redirects to the index.php:

header("Location: index.php");

But the index.php does not refresh. After a hard refresh with "F5" every thing is fine.

I also tried meta tags to prevent loading the page in the cache.

Any Ideas?

index.php:

<html lang="en">
<head>
    ...
</head>
<body >
<?php include("navbar.php")?>
    <div id="wrap">
    ...
    </div>
</body> 
</html>

navbar.php

<div class="navbar">
    <?php
    session_start();
    if (!isset($_SESSION['logged']) || !$_SESSION['logged']) 
    {?>
      ...Sign in etc...
    <?php
    }
    else
    {?>
        ...Accounting...
    <?php
    }?>
</div>

login.php:

<html>
<head>
</head>
<body>
<?php include("navbar.php"); ?>
<div class="container">
  <form class="form-signin" action="logon.php" method="post" >
        ...
    <button type="submit">Login</button>
  </form>
</div>
</body>
</html>

logon.php:

<?php
if login successfull //pseudo code
    header("Location: http://www.***.com/index.php");
}
else 
{
    header("Location: http://www.google.de");
}
exit;
?>
  • 写回答

2条回答 默认 最新

  • dongmo20030416 2013-06-27 14:14
    关注

    According to the specs, you have to pass an absolute uri.
    It's also best to add this, when redirecting:

    header('HTTP/1.1 301 Moved Permanently');
    header('Location: https://www.google.com');
    

    For SEO purpouses, and browser cache (google this to find out more).
    I hope you know this already, but you'll also have to make sure no output has been sent to the client, because in that case, the headers have already been sent, and logic dictates that it's too late to change them, then.

    Check this question for more details on how to deal with headers and output buffering.

    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备