Sessions

Status
Niet open voor verdere reacties.

RonaldGJ

Gebruiker
Lid geworden
28 apr 2007
Berichten
419
Hallo beste mensen,

ik heb een loginsysteem op mijn website geplaatst. Dat systeem heb ik gekregen van iemand die hem ook gebruikt. Maar er wil iets bij mij niet goed gaan en heb al heel lang naar de fout gezocht, maar kan hem niet vinden.
Als ik mijn inloggevens invul en klik op inloggen, vernieuwd ie de pagina, maar doet verder niks. Pas als ik nog een keer op inloggen klik (ook al vul ik dan geen gegevens in), dan staat er pas dat ik ingelogd ben. Terwijl het hoort, direct NA het 1 keer klikken op Login.

Gebruik ik het systeem helemaal los van mijn site. Dus echt alleen het inlogsysteem, dan doet hij het wel. Plug ik hem in mijn site, dan doet hij het niet. Het uitloggen gaat wel prima.

Op mijn website worden geen fouten aangegeven, dus heb ik hem in mijn local php server gezet en gekeken wat voor fouten er waren.

Deze 3:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\nieuw\phpmylogon2\phpmylogon.php on line 188

Notice: Table 'test.phpmylogon' doesn't exist in C:\wamp\www\nieuw\phpmylogon2\phpmylogon.php on line 222

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\nieuw\index.php:12) in C:\wamp\www\nieuw\phpmylogon2\phpmylogon.php on line 224

Iemand een idee wat ik er eventueel aan zou kunnen doen?
Als ik wat extra toe moet voegen of laten zien, hoor ik het wel!

Vast hartelijk bedankt, want ik kom er echt niet uit!

Gr. Ronald!:)
 
De eerste twee komen waarschijnlijk omdat je de database niet over hebt gezet naar je lokale server. Heb je dat wel gedaan dan kloppen je gegevens niet.

De derde is waarschijnlijk lastiger op te lossen. Persoonlijk denk ik dat die bij het inloggen zit dat er dan een verwijzing naar een andere pagina plaats vindt.

Zou je het gedeelte waarin je header en $_SESSION tegen komt (Dus het hele gedeelte wanneer het in een IF-, ELSE-, ELSEIF-lus o.i.d. staat) hier willen plaatsen zodat we een idee van het programmeerprobleem krijgen.
 
Het inloggen werkt met de functie pml_login().
Dit is het stuk van pml_login():
PHP:
// # How to use the function pml_login()?
// pml_login([what to do (include|redirect)],[which page])
// When a user is logged in, a message will be displayed that the user is logged in. If you want to redirect the user to a page,
// or if you want to include a page (p.e. a menu), then you can use the function on another way.
//# To INCLUDE A PAGE when the user is LOGGED IN use:
// pml_login('include','path-to-include.php');
// Where pagetoinclude.php the page is which should be included (tip: check on the included page if the user is logged on!)
// When using include, you have to referer to the page from the folder where the PhpMyLogon file is placed. If you have for example PhpMyLogon placed in the folder
// 'pml', and you use it from the root, you have to use ../filename.php if the file is also in the root folder.
// # To REDIRECT when the user is LOGGED IN use:
// pml_login('redirect','redirecttothispage.php');
// Where redirecttothispage.php the page is where the user will be redirected to (tip: check on the redirected page if the user is logged on!)
// When using redirect, you should referer to the page as you should do when you would redirect it from the page where you include PhpMyLogon. This is different then when
// you use the include function!!
function pml_login($todo = "",$action = "") {
	ob_start();
	include("lang.php");
	include("pml_config.inc.php");
	if(!isset($_SESSION)) { exit($lang['sessionproblem']); }
	
	pml_connect();
	
	// Check if user is logged in
	if(!isset($_SESSION['pml_userid'])) {
		if(isset($_COOKIE['pml_userid_cookie'])) {
			// Check cookie data with data in database
			$sql = "SELECT id,username,password,cookie_pass,actcode,rank FROM `".$settings['db_table']."` WHERE id = '".$_COOKIE['pml_userid_cookie']."' LIMIT 1";
			$query = mysql_query($sql);
			if(mysql_num_rows($query) == 1) {
				// User exists
				$row = mysql_fetch_array($query);
				$id = htmlspecialchars($row['id']);
				$username = htmlspecialchars($row['username']);
				$password_db = htmlspecialchars($row['password']);
				$cookie_pass = htmlspecialchars($row['cookie_pass']);
				$actcode = htmlspecialchars($row['actcode']);
				$rank = htmlspecialchars($row['rank']);
				
				if($actcode == "") {
					// Useraccount is activated
					if($cookie_pass == $_COOKIE['pml_usercode_cookie']) {
						// Everything ok, create sessions
						$_SESSION['pml_userid'] = $id;
						$_SESSION['pml_userrank'] = $rank;
						
						$sql_updateonline = "UPDATE `".$settings['db_table']."` SET lastactive = NOW() AND lastlogin = NOW() WHERE id = '".$id."' LIMIT 1";
						mysql_query($sql_updateonline);
						
						header("Location: ".$_SERVER['REQUEST_URI']);
					}else{
						// Incorrect password
						setcookie("pml_userid_cookie", "", time() - 3600);
						setcookie("pml_usercode_cookie", "", time() - 3600);
						header("Location: ".$_SERVER['REQUEST_URI']);
					}
				}else{
					setcookie("pml_userid_cookie", "", time() - 3600);
					setcookie("pml_usercode_cookie", "", time() - 3600);
					header("Location: ".$_SERVER['REQUEST_URI']);
				}
			}else{
				// User doesn't exists
				setcookie("pml_userid_cookie", "", time() - 3600);
				setcookie("pml_usercode_cookie", "", time() - 3600);
				header("Location: ".$_SERVER['REQUEST_URI']);
			}
		
		}
			
		if(isset($_POST['submit'])) {
			if($_POST['username'] != "" AND $_POST['password'] != "") {
				// Check submitted data with data in database
				$sql = "SELECT id,username,password,cookie_pass,actcode,rank FROM `".$settings['db_table']."` WHERE username = '".$_POST['username']."' LIMIT 1";
				$query = mysql_query($sql);
				if(mysql_num_rows($query) == 1) {
					// User exists
					$row = mysql_fetch_array($query);
					$id = htmlspecialchars($row['id']);
					$username = htmlspecialchars($row['username']);
					$password_db = htmlspecialchars($row['password']);
					$cookie_pass = htmlspecialchars($row['cookie_pass']);
					$actcode = htmlspecialchars($row['actcode']);
					$rank = htmlspecialchars($row['rank']);
					
					if($actcode == "") {
						// Useraccount is activated
						if($password_db == sha1(md5($_POST['password']))) {
							// Everything ok, create sessions
							$_SESSION['pml_userid'] = $id;
							$_SESSION['pml_userrank'] = $rank;
							if(isset($_POST['cookie'])) {
								// Also create cookie
								setcookie("pml_userid_cookie", $id, time() + 365 * 86400);
								if($cookie_pass == "") {
									// Create cookie code
									mt_srand((double)microtime()*1000000);
									$pass = 1;
									while(strlen($pass) <= 10) {
										$i = chr(mt_rand(0,255));
										if(eregi("^[a-z0-9]$",$i)) {
											$pass = $pass.$i;
										}
									}
									$cookie_pass = md5($pass);
									$sql_cookiepass = "UPDATE `".$settings['db_table']."` SET cookie_pass = '".$cookie_pass."' WHERE id = ".$id." LIMIT 1";
									mysql_query($sql_cookiepass);
								}
								setcookie("pml_usercode_cookie", $cookie_pass, time() + 365 * 86400);
							}
							$sql_updateonline = "UPDATE `".$settings['db_table']."` SET lastactive = NOW(),lastlogin = NOW() WHERE id = '".$id."' LIMIT 1";
							mysql_query($sql_updateonline) or trigger_error(mysql_error());
							
							header("Location: ".$_SERVER['REQUEST_URI']);
						}else{
							// Incorrect password
							echo $lang['login-incorrect']."<br />";
						}
					}else{
						echo $lang['login-notactive']."<br />";
					}
				}else{
					// User doesn't exists
					echo $lang['login-incorrect']."<br />";
				}
				
				
			}else{
				echo $lang['login-forgotfield']."<br />";
			}
		}
		// Login form
		echo "\n";
		?>
		<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
		  <table width="272">
				<tr>
				  <td width="264"><?php echo $lang['login-username']; ?></br></td>
			  </tr>
				<tr>
					<td>
				    <input type="text" id="username" name="username" <?php if(isset($_POST['username'])) { echo 'value="'.$_POST['username'].'"'; } ?> /></td>
			  </tr>
				<tr>
					<td><label for="cookie"><?php echo $lang['login-password']; ?></label></td>
				</tr>
				<tr>
					<td><input type="password" id="password" name="password" <?php if(isset($_POST['password'])) { echo 'value="'.$_POST['password'].'"'; } ?> /></td>
				</tr>
				<tr>
				  <td><input type="checkbox" id="cookie" name="cookie" value="true" <?php if(isset($_POST['cookie'])) { echo "checked"; } ?> />
                    <?php echo $lang['login-cookie']; ?></td>
		    </tr>
				<tr>
				  <td><input type="submit" name="submit" value="<?php echo $lang['login-submitbutton']; ?>" /></td>
		    </tr>
			</table>
</form>
</li>
<li>
<a href="?page=registreer">Registreren</a>
		<?php
		
	}else{
		// User is logged on, redirect to page $goto; if no $goto just view msg that user is logged in
		if($todo != "") {
			if($todo == "include") {
				include($action);
			}elseif($todo == "redirect") {
				header("Location: ".$action);
			}else{
				echo $lang['functionproblem'];
			}
		}else{
			echo $lang['login-already'];
		}
	}
	ob_end_flush();
}

Dan heb ik dit in mijn index.php staan, waar ik het gebeuren wil laten gebeuren!
PHP:
<?php
	session_start();
?>
<html>
	<head>
		<link href="style.css" rel="stylesheet" type="text/css">
		<title>Ronald Groot Jebbink.nl | Home</title>
	</head>
<body>
<center>
	<div id="header">
		<span class="login">
			Welkom Gast.
		</span>
	</div>
	<div id="container">
		<div id="content">
			<table>
				<tr>
					<td class="nav" valign="top">
			<ul class="menu">
				<li><a href="index.php?page=home">Home</a></li>
				<li><a href="?page=tutorials">Tutorials</a></li>
				<li><a href="?page=downloads">Downloads</a></li>
				<li><a href="?page=gastenboek">Gastenboek</a></li>
				<li><a href="?page=contact">Contact</a></li>
				<li><a href="?page=forum">Forum</a></li>
			</ul>
				<span class="tekst">
					<?php
						require_once("phpmylogon2/use/use.php");
					?>
				</span>
Dat laatste stuk gaat het om. Ik haal het bestand use.php binnen. En daar staat in:
PHP:
<?php
require_once("phpmylogon2/phpmylogon.php");
pml_login();
?>

Ik hoop hier voldoende informatie mee gegeven te hebben. Willen jullie nog meer hebben of hebben jullie het idee dat er iets ontbreekt. Ik hoor het graag.

Bedankt,

Gr. Ronald!:)
 
Een fout waar ik al weken mee bezig ben!

Iemand?
 
Laatst bewerkt:
Je zal die database error op moeten lossen.
De tweede error zegt ook al iets: "Table 'test.phpmylogon' does not exist". Je zal deze database tabel aan moeten maken.

Als je deze (2) error(s) oplost, verdwijnt de 3e ook gok ik :)
 
Nou het rare er aan is dus:

Als ik op Login druk herkent hij de bende uit de database wel. Hij herlaad, laat het inlog ding staan. Geeft die fouten. De Sessions zijn ook al gemaakt alleen hij laad het inlogblok staan. Klik ik dan nog een keer op inloggen (ook al vul ik niks in bij gebruikersnaam en wachtwoord) dan pas verdwijnd het inlogblok en komt er te staan dat ik ingelogd ben.
Maar dat ben ik dus eigenlijk al.

Maar wel bedankt,

Gr. Ronald!:)
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan