Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Deparazitare externa pisici fara ...

Seriale turcesti/coreene online H...

Merita un Termostat Smart pentru ...

Sfat achizitie MTB Devron Riddle
 Problema mare cu parintii= nervi ...

switch microtik

Permis categoria B la 17 ani

Sfaturi pentru pregatirea de eval...
 Crapaturi placa

cum imi accesez dosarul electroni...

Momentul Aprilie 1964

Sursa noua - zgomot ?
 A fost lansat Ubuntu 24.04 LTS

Pareri apartament in zona Berceni?

Free streaming SkyShowtime de la ...

Skoda Fabia 1.0 TSI (110 CP)- 19 ...
 

ajutor php

- - - - -
  • Please log in to reply
7 replies to this topic

#1
bunicu9

bunicu9

    Member

  • Grup: Members
  • Posts: 253
  • Înscris: 14.07.2013
Buna seara!

Am gasit un script php simplu register/login

Baza mea de date este
--
-- Structura de tabel pentru tabelul `players`
--
CREATE TABLE IF NOT EXISTS `players` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(100) NOT NULL,
  `password` varchar(128) NOT NULL,
  `Email` varchar(150) DEFAULT NULL,
  `Level` int(11) NOT NULL DEFAULT '1',
  `AdminLevel` int(11) NOT NULL DEFAULT '0',
  `HelperLevel` int(11) NOT NULL DEFAULT '0',
  `Cash` int(24) NOT NULL DEFAULT '0',
  `Account` int(24) NOT NULL DEFAULT '0',
  `Registred` int(11) DEFAULT '0',
  `Tutorial` int(11) NOT NULL DEFAULT '0',
  `IP` varchar(46) DEFAULT NULL,
  `LastLogin` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`ID`),
  FULLTEXT KEY `password` (`password`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;


Am facut sciptul sa ma pot loga cu contul din baza mea de date mysql

Asa arata index.php

<?php
?>
<?php include("auth.php"); //include auth.php file on all secure pages ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Welcome Home</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p>Welcome <?php echo $_SESSION['username']; ?>!</p>
<p>This is secure area.</p>
<p><a href="dashboard.php">Dashboard</a></p>
<a href="logout.php">Logout</a>
</div>


</body>
</html>


Cum pot afisa in index
din baza mea de date "Cash si level" si valoarea lor

#2
Kain_12

Kain_12

    Senior Member

  • Grup: Senior Members
  • Posts: 2,009
  • Înscris: 25.11.2009
Cu SQL. Select Cash from players where username like $_SESSION['username']
Rulezi query-ul respectiv, il salvezi intr-o variabila si ii dai echo.

#3
bunicu9

bunicu9

    Member

  • Grup: Members
  • Posts: 253
  • Înscris: 14.07.2013
Am uitat sa mentionez ca nu prea ma pricep.

Deci ce trebuie sa fac?

$query = "SELECT * FROM `players` WHERE Cash" like $_SESSION['username']; ??

#4
robbie_ro

robbie_ro

    Active Member

  • Grup: Members
  • Posts: 1,841
  • Înscris: 24.08.2004
$query = "SELECT Cash, Level FROM players WHERE username LIKE $_SESSION['username']";

#5
bunicu9

bunicu9

    Member

  • Grup: Members
  • Posts: 253
  • Înscris: 14.07.2013
La profile.php am pus
<?php session_start(); ?>
<?php
if(!isset($_SESSION['valid'])) {
header('Location: login.php');
}
?>
<?php
//including the database connection file
include_once("connection.php");
//fetching data in descending order (lastest entry first)
//$result = mysql_query("SELECT * FROM players");
$result = mysql_query("SELECT * FROM players WHERE username='$user'")
?>
<html>
<head>
<title>Homepage</title>
</head>
<body>
<a href="index.php">Home</a> | <a href="add.html">Add New Data</a> | <a href="logout.php">Logout</a>
<br/><br/>

<table width='80%' border=0>
  <tr bgcolor='#CCCCCC'>
   <td>Name</td>
   <td>Level</td>
   <td>Admin Level</td>
  </tr>
  <?php
  while($res = mysql_fetch_array($result)) { 
   echo "<tr>";
   echo "<td>".$res['username']."</td>";
   echo "<td>".$res['Level']."</td>";
   echo "<td>".$res['AdminLevel']."</td>";  
  }
  ?>
</table>
</body>
</html>


Nu imi afiseaza nimic
De ce?


asa arata login-ul acum
<?php session_start(); ?>
<html>
<head>
<title>Login</title>
</head>
<body>
<a href="index.php">Home</a> <br />
<?php
include("connection.php");
if(isset($_POST['submit'])) {
$user = mysql_real_escape_string($_POST['username']);
$pass = mysql_real_escape_string($_POST['password']);
if($user == "" || $pass == "") {
  echo "Either username or password field is empty.";
  echo "<br/>";
  echo "<a href='login.php'>Go back</a>";
} else {
  $result = mysql_query("SELECT * FROM players WHERE username='$user' AND password=md5('$pass')",$conn)
	 or die("Could not execute the select query.");
 
  $row = mysql_fetch_assoc($result);
 
  if(is_array($row) && !empty($row)) {
   $validuser = $row['username'];
   $_SESSION['valid'] = $validuser;
   $_SESSION['name'] = $row['name'];
   $_SESSION['id'] = $row['id'];
  } else {
   echo "Invalid username or password.";
   echo "<br/>";
   echo "<a href='login.php'>Go back</a>";
  }
  if(isset($_SESSION['valid'])) {
   header('Location: index.php');  
  }
}
} else {
?>
<p><font size="+2">Login</font></p>
<form name="form1" method="post" action="">
  <table width="75%" border="0">
   <tr>
	<td width="10%">Username</td>
	<td><input type="text" name="username"></td>
   </tr>
   <tr>
	<td>Password</td>
	<td><input type="password" name="password"></td>
   </tr>
   <tr>
	<td>&nbsp;</td>
	<td><input type="submit" name="submit" value="Submit"></td>
   </tr>
  </table>
</form>
<?php
}
?>
</body>
</html>



#6
robbie_ro

robbie_ro

    Active Member

  • Grup: Members
  • Posts: 1,841
  • Înscris: 24.08.2004
Daca tot faci "SELECT * " la login, de ce nu setezi direct 'level' si 'cash' in sesiune?


if(is_array($row) && !empty($row)) {
$validuser = $row['username'];
$_SESSION['valid'] = $validuser;
$_SESSION['name'] = $row['name']; //nu am vazut in tabela players campul acesta, deci va fi NULL
$_SESSION['id'] = $row['id'];
$_SESSION['cash'] = $row['Cash'];
$_SESSION['level'] = $row['Level'];
$_SESSION['adminlevel'] = $row['AdminLevel'];
} else {
echo "Invalid username or password.";
echo "<br/>";
echo "<a href='login.php'>Go back</a>";
}



apoi, in pagina ai

<table width='80%' border=0>
<tr bgcolor='#CCCCCC'>
<td>Name</td><td><?=$_SESSION['name']?></td>
<td>Level</td><?=$_SESSION['level']?></td>
<td>Admin Level</td><?=$_SESSION['adminlevel']?></td>
</tr>
<?php
/* while($res = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>".$res['username']."</td>";
echo "<td>".$res['Level']."</td>";
echo "<td>".$res['AdminLevel']."</td>";
} */
?>
</table>
</body>



Edited by robbie_ro, 29 April 2016 - 11:43.


#7
bunicu9

bunicu9

    Member

  • Grup: Members
  • Posts: 253
  • Înscris: 14.07.2013
Multumesc!
Am reusit.

#8
bunicu9

bunicu9

    Member

  • Grup: Members
  • Posts: 253
  • Înscris: 14.07.2013
Cum pot face un text sa spuna cate conturi sunt in players ?
si un text care sa spuna cati jucatori au adminlevel <1?

Anunturi

Second Opinion Second Opinion

Folosind serviciul second opinion ne puteți trimite RMN-uri, CT -uri, angiografii, fișiere .pdf, documente medicale.

Astfel vă vom putea da o opinie neurochirurgicală, fără ca aceasta să poată înlocui un consult de specialitate. Răspunsurile vor fi date prin e-mail în cel mai scurt timp posibil (de obicei în mai putin de 24 de ore, dar nu mai mult de 48 de ore). Second opinion – Neurohope este un serviciu gratuit.

www.neurohope.ro

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate