-2

With this code everything works:

    <?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");
    ?>

but when the "session_start();" is not uncommented the browser can not find this page.. I found nothing on the internet so thats why I asked you

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tom
  • 1
  • 4
    I'll give you one basic tip - when you're developing a website, turn php errors on. You'll find out it's much easier to troubleshoot your code like that. – walther Feb 29 '16 at 21:14
  • 1
    `error_reporting(E_ALL); ini_set('display_errors', '1');` – AbraCadaver Feb 29 '16 at 21:15

2 Answers2

2

session_start() needs to be the very first thing that happens:

    <?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:

To use cookie-based sessions, session_start() must be called before outputing anything to the browser.

Technofrood
  • 100
  • 1
  • 9
  • Do you have access to the error logs? Also make sure the – Technofrood Feb 29 '16 at 21:15
  • yes i think i have. To the apache error logs or to the php error logs? – Tom Feb 29 '16 at 21:17
  • PHP error logs would be the first place to look, if not check the Apache access/error logs this may show you the error that is actually happening. – Technofrood Feb 29 '16 at 21:18
  • "the system can not find the path." Do you think it could be helpfull to deinstall xampp completly and then reinstall it? Maybe i made a mistake when i installed it.. – Tom Feb 29 '16 at 21:23
  • Is there more to the message (the whole line would be helpful)? It possible its failing to find the temp directory when its trying to create the session. – Technofrood Feb 29 '16 at 21:25
  • Just found [this question](http://stackoverflow.com/questions/670595/php-session-start-fails) which might be the same issue you are having. – Technofrood Feb 29 '16 at 21:35
0

check where you r running this code. if its localhost check other php codes r running successfully ..

<?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");
    ?> 

as others start session should be in ur first line ..

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

the above code is used to check whether session is working properly

<?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

see the second code i have included the file which is not existed so u can able to check with ths ...

if Still ur code is not working

i suggest u to check .. 1.whether other php scripts works fine 2.run the same script without including any files (to check whether the problems is with ur include file)

If nothing works pls post error information..

selva
  • 193
  • 3
  • 17