Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Avocatul Poporului vs European Om...

Recomandari firme pentru draperii...

Receptie Eutelsat 5 West. Este po...

Poti receptiona semnal de la mai ...
 Cabluri HDMI 2.1 de 4m-5m care sa...

Zoom comparat cu Google Meet

Monitor/Display wireless?

Pornire greoaie dupa cateva zile ...
 De la un proiect scris in python ...

Audi A4 B9 quattro 190 CP!

Tepari la pariuri pe TikTok

Banca imi cere justificativ fondu...
 schema pcb ELECTRA CIM150 PAS

Probleme stomac

Sfat achizitie bicicleta oras

Canalele Sky Showtime 1 și S...
 

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,840
  • Î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,840
  • Î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

Bun venit pe Forumul Softpedia!

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