Jump to content

Problema PHP/mySQL lastonline?


unknown

Recommended Posts

<?php
session_start();

if(isset($_SESSION['usr_id'])!="") {
	header("Location: dashboard.php");
}

include_once 'includes/config.php';

//check if form is submitted
if (isset($_POST['login'])) {

	$username = mysqli_real_escape_string($con, $_POST['name']);
	$password = mysqli_real_escape_string($con, $_POST['password']);
	$result = mysqli_query($con, "SELECT * FROM users WHERE name = '" . $username. "' and password = '" . $password. "'");

	if ($row = mysqli_fetch_array($result)) {
		$_SESSION['usr_id'] = $row['id'];
		$_SESSION['usr_name'] = $row['name'];
		$_SESSION['admin'] = $row['Admin'];
		$_SESSION['level'] = $row['Level'];
		$_SESSION['email'] = $row['Email'];
		$_SESSION['premium'] = $row['Premium'];
		$_SESSION['bank'] = $row['Bank'];
		$_SESSION['xon'] = $row['lastOn'];
		header("Location: dashboard.php");
	} else {
		$errormsg = "Incorrect Email or Password!!!";
	}
}
?>

Uite sursa la codul pe care il folosesc!

Link to comment
Share on other sites

if ($row = mysqli_fetch_array($result))

  Inlocuieste-o cu:

 

$row = mysqli_fetch_array($result);
if ($row)

Acolo defapt ai facut in felul urmator

Daca variabilei $row i se poate atribui valoarea returnata de functia mysqli_fetch_array($result) , executa codul. Dar nu ai verificat daca functia a returnat vreun rezultat.

Reborn.

Link to comment
Share on other sites

  • Moderators

Probabil ai rezolva mai repede daca ai ignora toate undefined index-urile, cine a facut if-urile ar fi trebuit sa aiba activ optiunea completa de erori.

Pentru a ignora toate erorile alea care defapt nu ar trebuii sa strice nimic, poti pune intrun fisier php global care este folosit in toate fisierele urmatoru rand:

error_reporting(E_ALL ^ E_NOTICE);

 

PHP Developer - Not available for freelancing right now

Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament

Link to comment
Share on other sites

  • Moderators

Da, dar cam orice aplicatie are un fisier de configuratie sau global.php sau ceva de genu unde poti adauga randu ala, unele aplicatii chiar au deja randul acela pus, doar ca nu ignora E_NOTICE.

PHP Developer - Not available for freelancing right now

Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament

Link to comment
Share on other sites

12 minutes ago, gadeas said:

Da, dar cam orice aplicatie are un fisier de configuratie sau global.php sau ceva de genu unde poti adauga randu ala, unele aplicatii chiar au deja randul acela pus, doar ca nu ignora E_NOTICE.

ideea ca este ca scriptul php la care lucrez nu ii o aplicatie , este un login script php mysql,

daca stii un script login php mysql ar fi de ajutor si sa nu arate erorile istea. @gadeas

nu imi mai arata erorile dar nici datele din mysql unde trebuia sa arate.

Edited by unknown
Link to comment
Share on other sites

  • Moderators

Tot ar trebuii sa ai un fisier global pentru a evita verificarea daca useru e logat sau nu de fiecare data si asa eviti aceasi cod in fiecare pagina.

Mai exact ar fi bine sa folosesti niste metode de a lucra, dexemplu MVC (Model view controller):

http://php-html.net/tutorials/model-view-controller-in-php/

Daca cauti PHP MVC Tutorial sau Example pe google vei gasi o gramada de exemple si tutoriale.

PHP Developer - Not available for freelancing right now

Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament

Link to comment
Share on other sites

  • gaby changed the title to Problema PHP/mySQL lastonline?
  • 1 year later...

1. Verifica daca in pagina in care il afisezi are pornit "session_start()",

2. Incearca sa folosesti o singura variabila $_SESSION, ceva de genul:

<?php
session_start();

include_once 'includes/config.php';

if(isset($_SESSION['user']) != true) {
	header("Location: dashboard.php");
} else {
	//check if form is submitted
	if (isset($_POST['login'])) {

		$username = mysqli_real_escape_string($con, $_POST['name']);
		$password = mysqli_real_escape_string($con, $_POST['password']);
		$result = mysqli_query($con, "SELECT * FROM users WHERE name = '" . $username. "' and password = '" . $password. "'");

		if ($row = mysqli_fetch_array($result)) {
			$_SESSION['user'] = array(
				$row['id'],
				$row['name'],
				$row['Admin'],
				$row['Level'],
				$row['Email'],
				$row['Premium'],
				$row['Bank'],
				$row['lastOn']
			);
			header("Location: dashboard.php");
		} else {
			$errormsg = "Incorrect Email or Password!!!";
		}
	}
}
?>

Sau introdu in sesiune doar ID-ul persoanei care s-a logat, iar cu ajutorul functiilor preia din baza de date numele,  level, laston etc.

Filme: Click.

Contact: Steam

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.