“在session_start();” erorr:浏览器找不到该页面

时间:2016-02-29 21:07:27

标签: php mysql session

使用此代码,一切正常:

    <?php
    include("header.php");
 // session_start();
    ?>
    <body align='center'>
        <div id='wrapper'>
            <div id='login_form'>
                <form action='login.php' method='post'>
                    <h1> Einloggen ins Forum.</h1>
                    <table>
                    <tr><td>Benutzername :</td> <td><input type='text' name='username'/></td></tr><br>
                    <tr><td>Passwort     :</td> <td><input type='password' name='password'/></td></tr><br>
                    </table>    
                                   <input type='submit' name='login' value='Log in'/>

                </form>
            </div>
        </div>      
                </body>
    <?php
    include("footer.php");
    ?>

但是当“session_start();”没有取消注释浏览器找不到这个页面..我在网上找不到任何东西,所以这就是我问你的原因

2 个答案:

答案 0 :(得分:2)

session_start()需要是第一件事:

    <?php
    session_start();
    include("header.php");
    ?>
    <body align='center'>
        <div id='wrapper'>
            <div id='login_form'>
                <form action='login.php' method='post'>
                    <h1> Einloggen ins Forum.</h1>
                    <table>
                    <tr><td>Benutzername :</td> <td><input type='text' name='username'/></td></tr><br>
                    <tr><td>Passwort     :</td> <td><input type='password' name='password'/></td></tr><br>
                    </table>    
                                   <input type='submit' name='login' value='Log in'/>

                </form>
            </div>
        </div>      
                </body>
    <?php
    include("footer.php");
    ?>

From the PHP docs

  

要使用基于cookie的会话,必须先调用session_start()   向浏览器输出任何内容。

答案 1 :(得分:0)

检查运行此代码的位置。如果它的localhost检查其他php代码r成功运行..

<?php
session_start();
include("header.php");
?>
    <body align='center'>
        <div id='wrapper'>
            <div id='login_form'>
                <form action='login.php' method='post'>
                    <h1> Einloggen ins Forum.</h1>
                    <table>
                    <tr><td>Benutzername :</td> <td><input type='text' name='username'/></td></tr><br>
                    <tr><td>Passwort     :</td> <td><input type='password' name='password'/></td></tr><br>
                    </table>    
                                   <input type='submit' name='login' value='Log in'/>

                </form>
            </div>
        </div>      
                </body>
    <?php
    include("footer.php");
    ?> 

因为其他人开始会话应该在你的第一行..

<?php
session_start();
$_session['name']='tom';
echo $_session['name'];
?> 

以上代码用于检查会话是否正常工作

<?php
session_start();
$_session['name']='tom';
echo $_session['name'];
include('hai.php');
?>  
Warning: include(hai.php): failed to open stream: No such file or directory in C:\xampp\htdocs\dashboard\cg\couponglitz.com\www.coupondunia.in\profile\home.php on line 5

Warning: include(): Failed opening 'hai.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\dashboard\cg\couponglitz.com\www.coupondunia.in\profile\home.php on line 5

看到第二个代码我已经包含了不存在的文件,所以你可以查看...

如果仍然无法使用代码

我建议你查一下.. 1.其他PHP脚本是否正常工作 2.运行相同的脚本而不包含任何文件(以检查问题是否包含在你的包含文件中)

如果没有任何效果,请发布错误信息..