Hallo!
Ik heb weer is een heel stom probleem.. :S
Ik ben bezig met een website, en op de website moet je kunnen inloggen.
Nou, geen probleem allemaal.
Als ik vanaf de index.php inlog word er gewoon een sessie aangemaakt als de gebruiker inlogd.
Ik include op elke pagina de 'topbar.php', waarin de form en het inlogscript staan.
Maar als ik nou op een andere pagina de 'topbar.php' include en inlog dan word er wel een sessie aangemaakt, maar zonder de variable $naam.
De variable $naam vraag ik gewoon op uit het tekstveld.
Dit werkt allemaal goed, omdat het vanaf de index pagina geen problemen geeft.
Dus voor de duidelijkheid: Als ik vanaf Index.php inlog word er gewoon een sessie aangemaakt en word er keurig netjes in de 'Topbar.php' aangegeven: Ingelogd als <naam>.
Nou helemaal goed.
Maar op elke andere pagina waarin ik de topbar.php include komt er te staan: "Ingelogd als" en dus niet de naam van de gebruiker...
Mn code:
index.php:
Topbar.php:
Hier bijvoorbeeld de pagina Register.php.. als ik vanaf deze pagina op de Topbar.php inlog word er dus wél een sessie aangemaak, maar geen waarde meegegeven aan de sessie:"
Ik hoop dat het zo duidelijk is
Ik heb weer is een heel stom probleem.. :S
Ik ben bezig met een website, en op de website moet je kunnen inloggen.
Nou, geen probleem allemaal.
Als ik vanaf de index.php inlog word er gewoon een sessie aangemaakt als de gebruiker inlogd.
Ik include op elke pagina de 'topbar.php', waarin de form en het inlogscript staan.
Maar als ik nou op een andere pagina de 'topbar.php' include en inlog dan word er wel een sessie aangemaakt, maar zonder de variable $naam.
De variable $naam vraag ik gewoon op uit het tekstveld.
Dit werkt allemaal goed, omdat het vanaf de index pagina geen problemen geeft.
Dus voor de duidelijkheid: Als ik vanaf Index.php inlog word er gewoon een sessie aangemaakt en word er keurig netjes in de 'Topbar.php' aangegeven: Ingelogd als <naam>.
Nou helemaal goed.
Maar op elke andere pagina waarin ik de topbar.php include komt er te staan: "Ingelogd als" en dus niet de naam van de gebruiker...
Mn code:
index.php:
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="main.css" />
<link href='http://fonts.googleapis.com/css?family=Arvo' rel='stylesheet' type='text/css'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GLR Media Management</title><a href="contact.php">Contact</a>
</head>
<body>
<?php
include ("connection.php");
//NIEUWSITEMS OPVRAGEN
$result = mysql_query("SELECT * FROM nieuwsitems WHERE goedkeuring =1 ORDER BY datum DESC limit 7");
$nieuwsitem = array();
if(mysql_num_rows($result) > 0)
{
while($Rij = mysql_fetch_array($result))
{
$nieuwsitem = str_replace('\r','',$nieuwsitem);
$nieuwsitem = str_replace('\n','<br />',$nieuwsitem);
array_push($nieuwsitem,'
<table border="0" width="396px"><tr><td>
Auteur: <a href="profiel.php?user='.$Rij["Naam"].'" style="text-decoration:none; color:black;"><u>'.$Rij["Naam"].'</u></a></td><td align=right>'.$Rij["Datum"].'</td></tr></table>
<table width="396px" height="160px" border=0><tr><td><a style="text-decoration:none;" href="reacties.php?type=nieuws&id='.$Rij['ID'].'">'.$Rij["Bericht"].'</a></td></tr></table>');
}
}
//YOUTUBE ITEMS OPVRAGEN
$result2 = mysql_query("SELECT * FROM youtubeitem WHERE goedkeuring =1 ORDER BY datum DESC limit 6");
$youtubeitem = array();
if(mysql_num_rows($result2) > 0)
{
while($Rij2 = mysql_fetch_array($result2))
{
array_push($youtubeitem,''.$Rij2['link'].'<table width="100%"><tr><td><a style="text-decoration:none;" href="reacties.php?type=youtube&id='.$Rij2['ID'].'">Reageer..</a></td></tr></table>');
}
}
?>
<?php
include ("topbar.php");
?>
<?php
$twitter_url = 'http://twitter.com/statuses/user_timeline/GLRMM.xml?count=1';
$buffer = file_get_contents($twitter_url);
?>
<div id="content">
<div id="shuffle"></div>
<div id="tagcloud"><p align="center">Meest gezocht:</p></div>
<div id="twitterdiv"><p align="center"></p>
<!-- LAATSTE TWEETS WEERGEVEN -->
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 7,
interval: 6000,
width: 280,
height: 550,
theme: {
shell: {
background: '#fafafa',
color: '#000000'
},
tweets: {
background: '#f0f0f0',
color: '#000000',
links: '#51a305'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
hashtags: false,
timestamp: true,
avatars: true,
behavior: 'all'
}
}).render().setUser('GLRMM').start();
</script>
</div><!--einde twitterdiv-->
<div id="youtubediv">
<?php
//YOUTUBE ITEMS WEERGEVEN
if(mysql_num_rows($result2) > 0)
{
echo '<div class="youtubeitem">'.$youtubeitem['0'].'</div>';
echo '<div class="youtubeitem">'.$youtubeitem['1'].'</div>';
echo '<div class="youtubeitem">'.$youtubeitem['2'].'</div>';
echo '<div class="youtubeitem">'.$youtubeitem['3'].'</div>';
echo '<div class="youtubeitem">'.$youtubeitem['4'].'</div>';
echo '<div class="youtubeitem">'.$youtubeitem['5'].'</div>';
}
else
{
echo "Er zijn geen filmpjes beschikbaar!";
}
?>
<BR /><BR /><BR />
</div><!--einde youtubediv-->
<?php
//NIEUWS ITEMS WEERGEVEN
if(mysql_num_rows($result) > 0)
{
echo '<div class="nieuwsitem">'.$nieuwsitem['0'].'</div>';
echo '<div class="nieuwsitem">'.$nieuwsitem['1'].'</div>';
echo '<div class="nieuwsitem">'.$nieuwsitem['2'].'</div>';
echo '<div class="nieuwsitem">'.$nieuwsitem['3'].'</div>';
echo '<div class="nieuwsitem">'.$nieuwsitem['4'].'</div>';
echo '<div class="nieuwsitem">'.$nieuwsitem['5'].'</div>';
echo '<div class="nieuwsitem">'.$nieuwsitem['6'].'</div>';
}
else
{
echo "Er zijn geen nieuwsitem beschikbaar!";
}
?>
</div><!--einde contentdiv-->
<?php
include ("bottombar.php");
?>
</body>
</html>
Topbar.php:
PHP:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="main.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="boven">
<?php
if(isset($_SESSION['login']))
{
$ingelogdals = $_SESSION["login"];
echo
'<div id="login">
<form id="form1" name="form1" method="post" action="">';
if (isset($mapverder)){
echo "<table><tr><td><a href='../check.php' style='text-decoration:none; color:#09F;'>Ingelogd als $ingelogdals</a></td>";
echo '<td><input type="submit" name="loguit" id="button" value="Log uit." /></td><tr></table>';
}
else
{
echo "<table><tr><td><a href='check.php' style='text-decoration:none; color:#09F;'>Ingelogd als $ingelogdals</a></td>";
echo '<td><input type="submit" name="loguit" id="button" value="Log uit." /></td><tr></table>';
}
if (isset($_POST['loguit'])){
if (isset($mapverder)){
session_destroy();
header ("location:../index.php");
}
else
{
session_destroy();
header ("location:index.php");
}
}
echo'</tr>
</table>
</form>
</div>';
}
else
{
echo
'<div id="login">
<form id="form1" name="form1" method="post" action="">
<table width="100%" height="39" border="0">
<tr>
<td width="19%" height="39">Username:</td>
<td width="19%"><label for="naam"></label>
<input name="naam" type="text" id="input" size="15" /></td>
<td width="18%">Password:</td>
<td width="21%"><input name="pass" type="password" id="input" size="15" /></td>
<td width="23%"><input type="submit" name="login1" id="button" value="Ok!" /></td>
</tr>
</table>
</form>
</div>';
}
if(isset($_POST['login1'])){
$naam = addslashes(mysql_real_escape_string($_POST['naam']));
$pass = addslashes(mysql_real_escape_string(md5($_POST['pass'])));
$Rij = mysql_fetch_array(mysql_query("SELECT Gebruikersnaam, Wachtwoord FROM users WHERE Gebruikersnaam='$naam' AND Wachtwoord = '$pass'"));
if($naam == $Rij['Gebruikersnaam'] && $pass == $Rij['Wachtwoord'])
{
$_SESSION['login'] = $naam;
header ("Location:#");
}
else
{
header ("Location: ../index.php");
}
}
?>
<?php
if (isset($mapverder)){
echo '<a href="../index.php"><img src="../images/banner.png" border="0" /></a><br />';
}
else
{
echo '<a href="index.php"><img src="images/banner.png" border="0" /></a><br />';
}
?>
</div>
</body>
</html>
Hier bijvoorbeeld de pagina Register.php.. als ik vanaf deze pagina op de Topbar.php inlog word er dus wél een sessie aangemaak, maar geen waarde meegegeven aan de sessie:"
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="main.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registreren</title>
</head>
<body>
<?php
include ("topbar.php");
global $mapverder;
$mapverder = ''; //Als dit bestand een map verder staat dan index.php, dan is $mapverder ='1'; anders $mapverder ='';
?>
<div id="content">
<form id="form3" name="form3" action="" method="post">
<table width="754" height="321" border="0" align="center">
<tr>
<td width="190"><u>Persoonlijk gegevens</u>:</td>
<td width="199"> </td>
<td width="183"><u>Inlog gegevens:</u></td>
<td width="164"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Voornaam:</td>
<td><input type="text" name="Voornaam" size="15" id="input" /></td>
<td>Inlognaam: </td>
<td><input type="text" name="Gebruikersnaam" size="15" id="input" /></td>
</tr>
<tr>
<td>*Tussenvoegsel</td>
<td><label for="Tussenvoegsel"></label>
<input type="text" name="Tussenvoegsel" size="15" id="input" /></td>
<td>Wachtwoord:</td>
<td><input type="password" name="Wachtwoord" size="15" id="input" /></td>
</tr>
<tr>
<td>Achternaam:</td>
<td><input type="text" name="Achternaam" size="15" id="input" /></td>
<td>Herhaal wachtwoord:</td>
<td><input type="password" name="Wachtwoord2" size="15" id="input" /></td>
</tr>
<tr>
<td>Geslacht:</td>
<td><label for="Geslacht"></label>
<select name="Geslacht" id="Geslacht">
<option value="Man" selected="selected">Man</option>
<option value="Vrouw">Vrouw</option>
</select></td>
<td>E-mail:</td>
<td><input type="text" name="Email" size="15" id="input" /></td>
</tr>
<tr>
<td>Functie:</td>
<td><select name="Functie" id="Functie">
<option value="student">Student</option>
<option value="docent">Docent</option>
<option value="bedrijf">Bedrijf</option>
<option value="Geen">Geen</option>
</select></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><p>*Opleiding:</p></td>
<td><input type="text" name="Opleiding" size="15" id="input" /></td>
<td>Nieuwsbrief</td>
<td><input type="hidden" name="Nieuwsbrief" value="0" /><input name="Nieuwsbrief" type="checkbox" id="Nieuwsbrief" value="1" />
<label for="Nieuwsbrief"></label></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><p> </p></td>
<td><p> </p></td>
<td><input type="submit" name="verzenden" value="Verzenden" /></td>
<td> </td>
</tr>
<tr>
<td height="61" colspan="4"><p>
</p>
<p> </p></td>
</tr>
</table>
</form>
<?php
if (isset($_POST['verzenden'])){
include ('connection.php');
$voornaam = addslashes(mysql_real_escape_string($_POST['Voornaam']));
$tussenvoegsel = addslashes(mysql_real_escape_string($_POST['Tussenvoegsel']));
$achternaam = addslashes(mysql_real_escape_string($_POST['Achternaam']));
$geslacht = addslashes(mysql_real_escape_string($_POST['Geslacht']));
$functie = addslashes(mysql_real_escape_string($_POST['Functie']));
$gebruikersnaam = addslashes(mysql_real_escape_string($_POST['Gebruikersnaam']));
$wachtwoord = md5($_POST['Wachtwoord']);
$wachtwoord1 = md5($_POST['Wachtwoord2']);
$opleiding = addslashes(mysql_real_escape_string($_POST['Opleiding']));
$email = addslashes(mysql_real_escape_string($_POST['Email']));
$nieuwsbrief = $_POST['Nieuwsbrief'];
$datum = date("d.m.y");
if ($wachtwoord == '$wachtwoord1'){
echo '<P align="center">De wachtwoorden komen niet overeen!</P>';
exit();
}
if (empty($voornaam) || empty($achternaam) || empty($geslacht) || empty($wachtwoord) || empty($wachtwoord1) || empty($gebruikersnaam) || empty($email) || empty($functie))
{
echo '<P align="center">Je hebt niet alle velden ingevuld!</P>';
exit();
}
if (mysql_query("INSERT INTO users (Voornaam, Tussenvoegsel, Achternaam, Geslacht, Functie, Gebruikersnaam, Wachtwoord, Opleiding, Email, Nieuwsbrief, Datum)VALUES ('$voornaam', '$tussenvoegsel', '$achternaam', '$geslacht', '$functie', '$gebruikersnaam','$wachtwoord','$opleiding','$email','$nieuwsbrief','$datum')"))
{
echo '<P align="center">Registratie succesvol. Je kunt nu inloggen.</P>';
}
}
?>
</div><!--einde contentdiv-->
<?php
include ("bottombar.php");
?>
</body>
</html>
Ik hoop dat het zo duidelijk is