PHP en Sessies

Pagina: 1
Acties:
  • 56 views sinds 30-01-2008

  • Tubbietje
  • Registratie: November 2001
  • Nu online
Beste tweakers, ik zit hier met een sessie probleem in php.
Het is als volgt.

Ik heb een pagina bestaande uit drie pagina's die geincluded worden (head, eigenpagina, foot).
In de head.php staat het volgende inlogformulier.

In me head.php start ie de ob_start(); en session_start(); op.

in de login.php staat het volgende:

PHP:
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
29
<?php
include ("head.php");
//Maak mysql connectie
    include ("functions.php");
    mysql_connection();
    
//get loginnaam en wachtwoord
    $inlognaam = $_POST['inlognaam'];
    $wachtwoord = md5 ($_POST['wachtwoord']);
    
//Mysql query
$query = "select inlognaam, wachtwoord from gebruikers where inlognaam = '$inlognaam' and wachtwoord = '$wachtwoord'";

$res = mysql_query($query);

if (mysql_num_rows($res) == 1)
    {
    header("location: loginsuccesvol.php");
    }
else
    {
    $fout = ("Probeer het opnieuw. De gebruikersnaam en/of wachtwoord was onjuist.");
    }

//Mysql query
$query = "SELECT * FROM nieuws ORDER BY ID DESC LIMIT 5";

$result = mysql_query($query) or die ("Er ging iets fout.");
?>


Het volgende staat in me loginsuccesvol.php

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
include ("head.php");
//Maak mysql connectie
    include ("functions.php");
    mysql_connection();
    
    $inlognaam = $_POST['inlognaam'];
    
//Mysql query
$query = "SELECT * FROM nieuws ORDER BY ID DESC LIMIT 5";

$result = mysql_query($query) or die ("Er ging iets fout.");
?>


Deze foutmelding krijg ik als ik ob_start(); weghaal uit me head.php

Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\pcaid\head.php:10) in c:\inetpub\wwwroot\pcaid\login.php on line 18

En deze krijg ik altijd:

Notice: Undefined variable: fout in c:\inetpub\wwwroot\pcaid\login.php on line 81

Wat ze betekenen weet ik wel, maar ik krijg ze met geen mogelijkheid weg :(

Iemand een idee :?

Thanks already :)

en mijn head.php file op verzoek :)

PHP:
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
ob_start();
session_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PCaid.nl</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    background-color: #F9F9F9;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onLoad="MM_preloadImages('layout/menu_home2nd.gif','layout/menu_forum2nd.gif','layout/menu_links2nd.gif','layout/menu_tarieven2nd.gif','layout/menu_contact2nd.gif')">
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="15" height="83">[img]"layout/head_left.gif"[/img]</td>
    <td width="203"><a href="index.php">[img]"layout/logo.gif"[/img]</a></td>
    <td width="562" background="layout/head_right.gif">
<?php
//Kijken of men is ingelogd en zodoende de juiste tekst weergeven
if(isset($_SESSION['inlognaam']))
{
    echo('<table width="200"  border="0" align="right" cellpadding="0" cellspacing="0">');
    echo('<tr>');
    echo("<td>U bent ingelogd als <B>$inlognaam</B><br><br>");
    echo('<a href="uitgelogd.php">Klik hier om uit te loggen</a></td>');
    echo('</tr>');
    echo('</table>');
}
else
{
    echo('<form action="login.php" method="post">');
    echo('<table width="272" border="0" align="right" cellpadding="1" cellspacing="1">');
    echo('<tr>');
    echo('<td width="107" class="style3"><span class="style3">Gebruikersnaam:</span></td>');
    echo('<td colspan="3"><input type="text" name="inlognaam"></td>');
    echo('</tr>');
    echo('<tr>');
    echo('<td class="style3"><span class="style3">Wachtwoord:</span></td>');
    echo('<td colspan="3"><input type="password" name="wachtwoord"></td>');
    echo('</tr>');
    echo('<tr><td>&nbsp;</td>');
    echo('<td width="108">');
    echo('<a href="registrerenform.php">Registreren</a></td>');
    echo('<td width="32"><div align="right">');
    echo('<input name="submit" type="image" value="inloggen" src="layout/button_go.gif">');
    echo('</div></td>');
    echo('<td width="12">&nbsp;</td>');
    echo('</tr>');
    echo('</table>');
    echo('</form>');
}
?>
    </td>
  </tr>
</table>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>[img]"layout/pixel_blue.gif"[/img][img]"layout/pixel_white.gif"[/img]<a href="index.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Home','','layout/menu_home2nd.gif',1)">[img]"layout/menu_home.gif"[/img]</a>[img]"layout/pixel_white.gif"[/img]<a href="registrerenform.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Forum','','layout/menu_forum2nd.gif',1)">[img]"layout/menu_forum.gif"[/img]</a>[img]"layout/pixel_white.gif"[/img]<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Links','','layout/menu_links2nd.gif',1)">[img]"layout/menu_links.gif"[/img]</a>[img]"layout/pixel_white.gif"[/img]<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Tarieven','','layout/menu_tarieven2nd.gif',1)">[img]"layout/menu_tarieven.gif"[/img]</a>[img]"layout/pixel_white.gif"[/img]<a href="contact.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Contact','','layout/menu_contact2nd.gif',1)">[img]"layout/menu_contact.gif"[/img]</a>[img]"layout/pixel_white.gif"[/img][img]"layout/pixel_blue.gif"[/img]</td>
  </tr>
  <tr>
    <td>[img]"layout/color_line.gif"[/img]</td>
  </tr>
</table>
</body>
</html>

[ Voor 92% gewijzigd door Tubbietje op 17-01-2005 16:06 ]

Intel Core i7 4770K + 8x LG 24EB23 | New iPad 16GB WiFi | Xiaomi Mi Mix 2 | Microsoft Surface Pro 3 i5 128GB


  • ludo
  • Registratie: Oktober 2000
  • Laatst online: 01-03 18:17
En wat is nu het probleem :? Ik zie nergens een vraag :?

En gebruik de [ php ] en [ /php ] tags voor je code, dat maakt het wat makkelijker leesbaar :)

Edit: ah nu is er wel een vraag :Y)
Maar dit valt onder standaard debug werk. De variabele $fout kan niet goed gezet worden.

Deze regel:
PHP:
1
$fout = ("Probeer het opnieuw. De gebruikersnaam en/of wachtwoord was onjuist.");
is vaag. Haal de haakjes eens weg.

[ Voor 47% gewijzigd door ludo op 17-01-2005 16:06 ]


  • NMe
  • Registratie: Februari 2004
  • Laatst online: 15-04 22:07

NMe

Quia Ego Sic Dico.

Je mag absoluut geen output boven session_start() hebben staan. Ook geen enters of spaties. Ik heb het vermoeden dat dat je probleem is, maar dat kan ik dus niet met zekerheid zeggen. Je krijgt nota bene een fout in head.php, maar je post alleen 2 andere files? :?

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


  • Tubbietje
  • Registratie: November 2001
  • Nu online
ludo schreef op maandag 17 januari 2005 @ 16:02:
En wat is nu het probleem :? Ik zie nergens een vraag :?

En gebruik de [ php ] en [ /php ] tags voor je code, dat maakt het wat makkelijker leesbaar :)
Sorry, mijn laatste stukkie was opeens weggevallen door een foutmelding die ik op het forum kreeg.
En ik heb het ff tussen [php] dingen gezet :)

Intel Core i7 4770K + 8x LG 24EB23 | New iPad 16GB WiFi | Xiaomi Mi Mix 2 | Microsoft Surface Pro 3 i5 128GB


  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 14:22

Creepy

Tactical Espionage Splatterer

De notice hoef je je niet druk om te maken. Die warning wel ;)
Op het moment dat jij je nieuwe header doorgeeft d.m.v. header("location: loginsuccesvol.php"); heeft PHP zelf al een header verzonden. Waarschijnlijk geef je in een ander bestand ook al een header mee, druk je output af, of begin je ergens met html tags waarin de header tag staat.

Maar dit kan je denk ik door zelf je bestanden even te controleren best wel controleren :)

Met ob_start zet je output buffering aan waardoor de headers nog niet worden verstuurd. Zonder ob_start() wordt de output meteen naar de client verzonden.

Ik denk dat je hiermee best uit de voeten kunt. Mocht het nou echt niet lukken, open dan een nieuw topic waarin je aangeeft wat je al hebt geprobeerd en waar je denkt dat het verkeerd zit :) Zie ook P&W FAQ - De "quickstart"

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


Dit topic is gesloten.