[php] Cookie error

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • w00d
  • Registratie: Juni 2004
  • Laatst online: 12:59
Goede avond,

Ik heb een klein probleempje met een website, als ik em lokaal test draait die prima, maar als ik em online gooi krijg ik de volgende 2 foutmeldingen:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/thefugitives/public_html/index.php:2) in /home/thefugitives/public_html/index.php on line 3

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/thefugitives/public_html/index.php:2) in /home/thefugitives/public_html/index.php on line 3

Hier de stuk code waar het om moet gaan:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
session_start();
// ------------------------ Start Both -----------------------------------------------------
if($_COOKIE['logedin'] == 'yes' || $_SESSION['logedin'] == 'yes') {
    header("Location: login.php");
    exit();
}

// If the form was submited check if the username and password match
if($_POST['Submit']){

    if($_POST['username'] == 'user' && $_POST['password'] == 'pw' ){
    
// ------------------------ Start Both -----------------------------------------------------
        // If username and password is right , store the session in a cookie
        setcookie ('logedin', 'John',time()+30000); // Set the length of the cookie to 30000
        //Create the Session id's (as many as you want, can also do the same with cookied)
        $_SESSION['logedin'] = 'John';
        
        // Redirect to the page
        header("Location: index.php");
        exit();
    } else {
        $error = 'Password and/or Username Not Valid, Please Try Again!';
    }
}
?>


Dit script heeft altijd gewoon gewerkt in de vorige versie van de site, maar nu geeft die kuren die ik niet thuis kan brengen.

Iemand ideetje wat er fout gaat?

De website met fout is te zien @ : www.thefugitives.tk

Acties:
  • 0 Henk 'm!

  • PowerSp00n
  • Registratie: Februari 2002
  • Laatst online: 19-08 08:24

PowerSp00n

There is no spoon

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/thefugitives/public_html/index.php:2) in /home/thefugitives/public_html/index.php on line 3
Zet die session start nou eens gewoon helemaal bovenaan aan het begin van de file. Je gaat me niet vertellen dat dit nergens te vinden was...

Acties:
  • 0 Henk 'm!

  • w00d
  • Registratie: Juni 2004
  • Laatst online: 12:59
dit was de enige regel die erboven stond. d8 niet dat dat no zo uitmaken.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

maarja het werkt, thnxs anyway

Acties:
  • 0 Henk 'm!

  • JHS
  • Registratie: Augustus 2003
  • Laatst online: 16-09 16:02

JHS

Splitting the thaum.

Door al output te verzenden in de eerste regel (je doctype) kan je niet nog je headers versturen. Het kopje moet voor de inhoud komen zegmaar :) . Er zijn daar twee oplossingen voor. Zoals PowerSp00n al zegt kan je ervoor zorgen dat al je headers vóór je content verstuurt worden door die bovenaan te zetten. Of je kan het structureel opvangen door álle output in één keer te versturen met behulp van ob, dit moet je dan wel écht als eerste uitvoeren. Lees verder de documentatie bij die functie...

DM!


Acties:
  • 0 Henk 'm!

  • w00d
  • Registratie: Juni 2004
  • Laatst online: 12:59
Ik heb gewoon dit doctype eruit gegooit, heb em volgens mij toch niet nodig, dreamweaver gooit heb bij mijn weten eroveral standaard in.

Maar bedankt voor de info. Weet ik dat ook weer

Acties:
  • 0 Henk 'm!

  • T-MOB
  • Registratie: Maart 2001
  • Laatst online: 16:36
Woodster schreef op zaterdag 08 oktober 2005 @ 22:22:
Ik heb gewoon dit doctype eruit gegooit, heb em volgens mij toch niet nodig, dreamweaver gooit heb bij mijn weten eroveral standaard in.
Het doctype is wel degelijk van belang, het bepaalt hoe je website (ook in de toekomst) wordt weergegeven. Je kunt het beter oplossen door het cookie-script uit te voeren voordat je het doctype stuurt.
In plaats van:
code:
1
2
<doctype>
<?php /* cookiescript */ ?>
dus gewoon
code:
1
2
<?php /* cookiescript */ ?>
<doctype>

Regeren is vooruitschuiven


Acties:
  • 0 Henk 'm!

  • Erkens
  • Registratie: December 2001
  • Niet online

Erkens

Fotograaf

De doctype geeft aan wat voor bestand het is, in jouw geval een HTML 4.01 bestand. Een browser kan adhv bepalen hoe de pagina gerenderd moet worden. In principe is deze regel dus verplicht.
Pagina: 1