Not able to redirect to next page

痞子三分冷 提交于 2019-12-02 09:10:13
arjun

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>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!