无法重定向到下一页

发布于 2024-11-03 11:25:27 字数 1302 浏览 4 评论 0原文

我使用的是 Win XP 操作系统和 XAMPP。我使用 eclipse 作为编辑器。在 Eclipes 中,我无法重定向下一页,所以现在我已经安装了 Zend 开发环境。

现在我也遇到了同样的问题。

我的代码是

HomePage.php

<html>
<body>
<form name="Form1" id="FormId" action="Welcome.php" method="post">
    name : <input type="text" name="txtName">
    Phone Number : <input type="text" name="txtPnum">
    <input type="submit" name="SubmitIt" value="Submit It">     
</form>
</body>
</html>


And Welcome.php is

<?php
    ob_start(); 
    session_start();    
    if(!($_SESSION['UName']))
    {
        $_SESSION['UName']=$_POST['txtName'];
    }
    if(!($_SESSION['Ph Num']))
    {
        $_SESSION['Ph Num']=$_POST['txtPnum'];
    }
?>
<html>
<body>
Welcome <?php   
    if(isset($_SESSION['UName']))
    {
        echo  $_SESSION['UName'];
    }
    else
    {
        echo "Session not set<br/>";    
        echo "{$_SESSION['UName']}";        
        echo "The session contains <br>";
        print_r($_SESSION);
    }           
    ?>
</body>
</html>

它在浏览器中工作正常(重定向到下一页),但在调试模式下不起作用。在 Eclipse 和 Zend 开发环境中。

它不显示下一页的内容,而是显示页面名称。(在我的示例中为Welcome.php)。

我是否需要安装任何其他额外的软件或代码本身磨损......有什么问题。请建议我。

提前致谢....!

I am using Win XP os and XAMPP. I was using eclipse as the editor. In Eclipes I was not able to redirect next page so now I have installed Zend Development Environment.

Now also I am getting the same problem.

My Code is

HomePage.php

<html>
<body>
<form name="Form1" id="FormId" action="Welcome.php" method="post">
    name : <input type="text" name="txtName">
    Phone Number : <input type="text" name="txtPnum">
    <input type="submit" name="SubmitIt" value="Submit It">     
</form>
</body>
</html>


And Welcome.php is

<?php
    ob_start(); 
    session_start();    
    if(!($_SESSION['UName']))
    {
        $_SESSION['UName']=$_POST['txtName'];
    }
    if(!($_SESSION['Ph Num']))
    {
        $_SESSION['Ph Num']=$_POST['txtPnum'];
    }
?>
<html>
<body>
Welcome <?php   
    if(isset($_SESSION['UName']))
    {
        echo  $_SESSION['UName'];
    }
    else
    {
        echo "Session not set<br/>";    
        echo "{$_SESSION['UName']}";        
        echo "The session contains <br>";
        print_r($_SESSION);
    }           
    ?>
</body>
</html>

Its working fine (redirecting to next page) in the Browser but its not working in the debug mode. Both in Eclipse and Zend Development Environment.

Instead of show the content of the next page, it showing the page name.(Welcome.php in my example).

Should I need to install any other extra softwares or code itself worng.... Whats the problem. Please suggest me.

Thanks in advance....!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甚是思念 2024-11-10 11:25:27

哪一部分应该进行重定向,我没有看到任何标头('Location:redirect.php')或其他内容

,为什么在这里使用 ob_start() 。

您没有释放输出缓冲区 add ob_get_clean();到底

<?php
    ob_start(); 
    session_start();    
    if(!($_SESSION['UName']))
    {
        $_SESSION['UName']=$_POST['txtName'];
    }
    if(!($_SESSION['Ph Num']))
    {
        $_SESSION['Ph Num']=$_POST['txtPnum'];
    }
    ob_end_flush();
?>
<html>
<body>
Welcome <?php   
    if(isset($_SESSION['UName']))
    {
        echo  $_SESSION['UName'];
    }
    else
    {
        echo "Session not set<br/>";    
        echo "{$_SESSION['UName']}";        
        echo "The session contains <br>";
        print_r($_SESSION);
    }           
    ?>
</body>
</html>

which part is supposed to make a redirection, i don't see any header('Location: redirect.php') or something

and why do you use ob_start() here .

you didnt release the output buffer add ob_get_clean(); in the end

<?php
    ob_start(); 
    session_start();    
    if(!($_SESSION['UName']))
    {
        $_SESSION['UName']=$_POST['txtName'];
    }
    if(!($_SESSION['Ph Num']))
    {
        $_SESSION['Ph Num']=$_POST['txtPnum'];
    }
    ob_end_flush();
?>
<html>
<body>
Welcome <?php   
    if(isset($_SESSION['UName']))
    {
        echo  $_SESSION['UName'];
    }
    else
    {
        echo "Session not set<br/>";    
        echo "{$_SESSION['UName']}";        
        echo "The session contains <br>";
        print_r($_SESSION);
    }           
    ?>
</body>
</html>
风和你 2024-11-10 11:25:27

尝试在代码末尾添加此内容,我很确定这是因为您没有释放输出缓冲区,尽管我认为它应该自动完成

echo ob_get_clean();

更新:

我不太确定为什么你在这里使用 $_SESSION 变量,但是如果您想解决问题,您可以使用 $uname 代替 $_SESSION['UName'];

Welcome.php

<?php // at the beginning of your file, no spaces or newline
    session_start();
    $uName=$_POST['txtPnum'];
    $txtPnum=$_POST['txtPnum'];
    $_SESSION['UName'] = $uName;
    $_SESSION['PhNum'] = $uName;
?>
<html>
<body>
Welcome <?php echo  $_SESSION['UName']; ?>

</body>
</html>

由于您仍在调试代码,因此您摆脱了 ob 启动。并一次尝试一步。
祝你好看。

try to add this at the end of your code i am pretty sure it is because you are not releasing the output buffer, although i think it should have done it automatically

echo ob_get_clean();

Update:

I am not really sure why you are using the $_SESSION variable here, but is you want to fix the problem, you can use for example $uname instead of $_SESSION['UName'];

Welcome.php

<?php // at the beginning of your file, no spaces or newline
    session_start();
    $uName=$_POST['txtPnum'];
    $txtPnum=$_POST['txtPnum'];
    $_SESSION['UName'] = $uName;
    $_SESSION['PhNum'] = $uName;
?>
<html>
<body>
Welcome <?php echo  $_SESSION['UName']; ?>

</body>
</html>

you get rid of the ob start since you are still debugging your code. and try one step at a time.
Wish you good look.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文