Log in
Who is online?
In total there are 3 users online :: 0 Registered, 0 Hidden and 3 Guests None
Most users ever online was 18 on Wed Mar 01, 2023 5:42 pm
Statistics
We have 1651 registered usersThe newest registered user is lesn1k
Our users have posted a total of 558 messages in 467 subjects
[Tutorial] PHP & MySql
Page 1 of 1
[Tutorial] PHP & MySql
Pasul
1.Baza de date
Pasul 2.Crearea indexurilor
Pasul 1a. Creati
BAZA DE DATE cu numele autentificare.
Pasul 1b. Dupa ce ati creat BAZA DE DATE apasati pe SQL
si introduceti urmatorul cod si dati EXECUTARE.
Cod:
Pasul 2a. Creati un fisier cu
numele config.php si introduceti urmatorul cod.
Cod:
Pasul
2b. Creati un fisier cu numele index.php si
introduceti urmatorul cod.
Cod:
Pasul
2c. Creati un fisier cu numele autentificare.php si
introduceti urmatorul cod.
Cod:
Pasul
2d. Creati un fisier cu numele inregistrare.php si
introduceti urmatorul cod.
Cod:
Pasul
2e. Creati un fisier cu numele pagina.php si
introduceti urmatorul cod.
Cod:
2e. Creati un fisier cu numele profil.php si
introduceti urmatorul cod.
Cod:
Pasul
2e. Creati un fisier cu numele iesire.php si
introduceti urmatorul cod.
Cod:
Pasul
3. Acum Intrati pe [You must be registered and logged in to see this link.] sau [You must be registered and logged in to see this link.]
Va multumesc
pentru ca ati urmarit acest tutorial
Cateva imagini
1.Baza de date
Pasul 2.Crearea indexurilor
Pasul 1a. Creati
BAZA DE DATE cu numele autentificare.
Pasul 1b. Dupa ce ati creat BAZA DE DATE apasati pe SQL
si introduceti urmatorul cod si dati EXECUTARE.
Cod:
- Code:
CREATE TABLE
`utilizatori` (
`id` int(11) NOT NULL auto_increment,
`utilizator` char(60) NOT NULL default '',
`parola` char(60) NOT
NULL default '',
`nume` char(30) NOT NULL default '',
`prenume` char(30) NOT NULL default '',
`varsta` char(3) NOT NULL
default '',
`localitate` char(30) NOT NULL default '',
PRIMARY
KEY (`id`));
Pasul 2a. Creati un fisier cu
numele config.php si introduceti urmatorul cod.
Cod:
- Code:
<?php
session_start();
set_time_limit(0);
error_reporting(E_ALL);
//
Informatii baza de date
$AdresaBazaDate = "localhost";
$UtilizatorBazaDate
= "root";
$ParolaBazaDate = "";
$NumeBazaDate =
"autentificare";
$conexiune =
mysql_connect($AdresaBazaDate,$UtilizatorBazaDate) or die("Nu ma pot
conecta la MySQL!");
mysql_select_db($NumeBazaDate, $conexiune) or
die("Nu gasesc baza de date");
function addentities($data){
if(trim($data) != ''){
$data = htmlentities($data, ENT_QUOTES);
return str_replace('\', '', $data);
} else return $data;
}
// End addentities() --------------
?>
Pasul
2b. Creati un fisier cu numele index.php si
introduceti urmatorul cod.
Cod:
- Code:
<?php
require_once('config.php');
echo
'<h1>Tutorial</h1>
Pentru Inregistrare Click <a
href="inregistrare.php">aici</a><br>
Pentru
Autentificare Click<a
href="autentificare.php">aici</a><br>';
?>
Pasul
2c. Creati un fisier cu numele autentificare.php si
introduceti urmatorul cod.
Cod:
- Code:
<?php
require_once('config.php');
if(!isset($_GET['actiune']))
$_GET['actiune'] = '';
switch($_GET['actiune'])
{
case '':
echo
'<form action="autentificare.php?actiune=validare" method="post">
Utilizator: <input type="text" name="user"
value=""><br>
Parola: <input type="password"
name="parola" value=""><br>
<input type="submit"
name="Login" value="Login">
</form>';
break;
case
'validare':
$_SESSION['user'] = $_POST['user'];
if(($_POST['user']
== '') || ($_POST['parola'] == ''))
{
echo 'Completeaza casutele.
<Br>
Apasati <a
href="autentificare.php">aici</a> pentru a va intoarce la
pagina precedenta.';
}
else
{
$cerereSQL = "SELECT * FROM
`utilizatori` WHERE utilizator='".htmlentities($_POST['user'])."' AND
parola='".md5($_POST['parola'])."'";
$rezultat =
mysql_query($cerereSQL);
if(mysql_num_rows($rezultat) == 1)
{
while($rand = mysql_fetch_array($rezultat))
{
$_SESSION['logat'] = 'Da';
echo '<META HTTP-EQUIV=Refresh
CONTENT="0; URL=pagina.php">';
}
}
else
{
echo 'Date
incorecte. <Br>
Apasati <a
href="autentificare.php">aici</a> pentru a va intoarce la
pagina precedenta.';
}
}
break;
}
?>
Pasul
2d. Creati un fisier cu numele inregistrare.php si
introduceti urmatorul cod.
Cod:
- Code:
<?php
require_once('config.php');
if(!isset($_GET['actiune']))
$_GET['actiune'] = '';
if(!isset($_SESSION['user']))
$_SESSION['user'] = '';
if(!isset($_SESSION['parola1']))
$_SESSION['parola1'] = '';
if(!isset($_SESSION['parola2']))
$_SESSION['parola2'] = '';
if(!isset($_SESSION['nume']))
$_SESSION['nume'] = '';
if(!isset($_SESSION['prenume']))
$_SESSION['prenume'] = '';
if(!isset($_SESSION['varsta']))
$_SESSION['varsta'] = '';
if(!isset($_SESSION['localitate']))
$_SESSION['localitate'] = '';
switch($_GET['actiune'])
{
case
'':
echo '<table width="309" border="0" cellpadding="0"
cellspacing="0">
<form name="formular"
action="inregistrare.php?actiune=validare" method="post">
<tr>
<td height="36" colspan="4"
valign="top"><h1>Formular inregistrare </h1></td>
</tr>
<tr>
<td width="80" height="19"
valign="top"> </td>
<td width="15" rowspan="5"
valign="top"></td>
<td width="144"
valign="top"> </td>
<td width="70"
valign="top"> </td>
</tr>
<tr>
<td height="22" align="right" valign="top">Utilizator:</td>
<td colspan="2" valign="top">
<input type="text"
name="user" value="'.$_SESSION['user'].'"> </td>
</tr>
<tr>
<td height="7"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="22" align="right"
valign="top">Parola:</td>
<td colspan="2"
valign="top"><input type="password" name="parola1"
value="'.$_SESSION['parola1'].'"></td>
</tr>
<tr>
<td height="7"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="38" align="right"
valign="top">Reintroduceti<br> Parola:</td>
<td> </td>
<td align="middle"
valign="middle"><input type="password" name="parola2"
value="'.$_SESSION['parola2'].'"></td>
<td> </td>
</tr>
<tr>
<td
height="7"></td>
<td valign="top"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="19" align="right">Nume:</td>
<td> </td>
<td colspan="2"
valign="top"><input type="text" name="nume"
value="'.$_SESSION['nume'].'"></td>
</tr>
<tr>
<td height="7"></td>
<td
valign="top"></td>
<td></td>
<td></td>
</tr>
<tr>
<td
height="22" align="right">Prenume:</td>
<td
valign="top"></td>
<td colspan="2"
valign="top"><input type="text" name="prenume"
value="'.$_SESSION['prenume'].'"></td>
</tr>
<tr>
<td height="8"></td>
<td
valign="top"></td>
<td></td>
<td></td>
</tr>
<tr>
<td
height="22" align="right" valign="top">Varsta:</td>
<td valign="top"></td>
<td colspan="2"
valign="top"><input type="text" size="3" maxLength="3"
name="varsta" value="'.$_SESSION['varsta'].'">
ani</td>
</tr>
<tr>
<td
height="15"></td>
<td valign="top"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="22" align="right"
valign="top">Localitate:</td>
<td
valign="top"></td>
<td colspan="2"
valign="top"><input type="text" name="localitate"
value="'.$_SESSION['localitate'].'"></td>
</tr>
<tr>
<td height="19"> </td>
<td
valign="top"></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td
height="24"> </td>
<td valign="top"></td>
<td colspan="2" valign="top"><input name="Trimite"
type="submit" id="Trimite" value="Trimite">
<input
name="Reseteaza" type="reset" id="Reseteaza" value="Reseteaza">
</td>
</tr>
<tr>
<td
height="24"> </td>
<td valign="top"></td>
<td> </td>
<td> </td>
</tr>
</form>
</table>';
break;
case 'validare':
$_SESSION['user']
= $_POST['user'];
$_SESSION['parola1'] = $_POST['parola1'];
$_SESSION['parola2']
= $_POST['parola2'];
$_SESSION['nume'] = $_POST['nume'];
$_SESSION['prenume']
= $_POST['prenume'];
$_SESSION['varsta'] = $_POST['varsta'];
$_SESSION['localitate']
= $_POST['localitate'];
if(($_SESSION['user'] == '') ||
($_SESSION['parola1'] == '') || ($_SESSION['parola2'] !=
$_SESSION['parola1']) || ($_SESSION['nume'] == '') ||
($_SESSION['prenume'] == '') || ($_SESSION['varsta'] == '') ||
(!is_numeric($_SESSION['varsta'])) || (strlen($_SESSION['varsta']) <
2) || ($_SESSION['localitate'] == ''))
{
echo 'Nu ai introdus date
in formular sau cele introduse nu sunt corecte. <br>
Apasa <a href="inregistrare.php">aici</a> pentru a te
intoarce la pagina anterioara.';
}
else
{
echo 'Va
multumim. <br>
Datele au fost introduse cu succes in
baza de date. <br>
Pentru a va autentifica apasati <a
href="autentificare.php">aici</a>.';
$cerereSQL =
"INSERT INTO `utilizatori` (`utilizator`, `parola`, `nume`, `prenume`,
`varsta`, `localitate`)
VALUES
('".addentities($_SESSION['user'])."', '".md5($_SESSION['parola1'])."',
'".addentities($_SESSION['nume'])."',
'".addentities($_SESSION['prenume'])."',
'".addentities($_SESSION['varsta'])."',
'".addentities($_SESSION['localitate'])."')";
mysql_query($cerereSQL);
$_SESSION['user']
= '';
$_SESSION['parola1'] = '';
$_SESSION['parola2'] = '';
$_SESSION['nume']
= '';
$_SESSION['prenume'] = '';
$_SESSION['varsta'] = '';
$_SESSION['localitate']
= '';
}
break;
}
?>
Pasul
2e. Creati un fisier cu numele pagina.php si
introduceti urmatorul cod.
Cod:
- Code:
<?php
require_once('config.php');
if(!isset($_SESSION['logat']))
$_SESSION['logat'] = 'Nu';
if($_SESSION['logat'] != 'Da')
{
echo
'Pentru a accesa aceasta pagina, trebuie sa va autentificati.
<br>
Pentru a va autentifica, apasati <a
href="autentificare.php">aici</a><br>
Pentru a va
inregistra, apasati <a href="inregistrare.php">aici</a>';
}
else
{
echo
'Bine ai venit,
<b><i>'.$_SESSION['user'].'</b></i>!<br><br>
<a href="profil.php">Schimba date
personale</a><br><br>
<a
href="iesire.php">Iesire</a>';
}
?>
2e. Creati un fisier cu numele profil.php si
introduceti urmatorul cod.
Cod:
- Code:
<?php
require_once('config.php');
if(!isset($_GET['actiune']))
$_GET['actiune'] = '';
if(!isset($_SESSION['logat']))
$_SESSION['logat'] = 'Nu';
if($_SESSION['logat'] != 'Da')
{
echo
'Pentru a accesa aceasta pagina, trebuie sa va autentificati.
<br>
Pentru a va autentifica, apasati <a
href="autentificare.php">aici</a><br>
Pentru a va
inregistra, apasati <a href="inregistrare.php">aici</a>';
}
else
{
switch($_GET['actiune'])
{
case
'':
echo '<h1>Profilul dumneavoastra</h1>
Apasati <a href="profil.php?actiune=date_personale">aici</a>
pentru a schimba datele personale.<br>
Apasati <a
href="profil.php?actiune=parola">aici</a> pentru a schimba
parola dumneavoastra.<br><br>
<a
href="pagina.php">Intoarceti`va la pagina principala.</a>';
break;
case
'date_personale':
$cerereSQL = 'SELECT * FROM `utilizatori` WHERE
utilizator="'.$_SESSION['user'].'"';
$rezultat =
mysql_query($cerereSQL);
while($rand =
mysql_fetch_array($rezultat))
{
echo '<table width="347"
border="0" cellpadding="0" cellspacing="0">
<form
name="formular" action="profil.php?actiune=validare" method="post">
<tr>
<td height="50" colspan="4"
valign="top"><h1>Modifica date personale</h1></td>
</tr>
<tr>
<td width="80"
height="19"> </td>
<td width="15"> </td>
<td width="214"> </td>
<td
width="38"> </td>
</tr>
<tr>
<td height="10"></td>
<td></td>
<td></td>
</tr>
<tr>
<td
height="22" align="right" valign="top">Nume:</td>
<td
valign="top"></td>
<td valign="top"><input
type="text" name="nume" value="'.$rand['nume'].'"></td>
<td></td>
</tr>
<tr>
<td
height="9"></td>
<td valign="top"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="22" align="right"
valign="top">Prenume:</td>
<td
valign="top"></td>
<td valign="top"><input
type="text" name="prenume" value="'.$rand['prenume'].'"></td>
<td></td>
</tr>
<tr>
<td height="9"></td>
<td
valign="top"></td>
<td></td>
<td></td>
</tr>
<tr>
<td
height="22" align="right" valign="top">Varsta:</td>
<td valign="top"></td>
<td
valign="top"><input type="text" size="3" maxLength="3"
name="varsta" value="'.$rand['varsta'].'">
ani</td>
<td></td>
</tr>
<tr>
<td height="8"></td>
<td
valign="top"></td>
<td></td>
<td></td>
</tr>
<tr>
<td
height="22" align="right" valign="top">Localitate:</td>
<td valign="top"></td>
<td
valign="top"><input type="text" name="localitate"
value="'.$rand['localitate'].'"></td>
<td></td>
</tr>
<tr>
<td
height="14"></td>
<td valign="top"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="24"></td>
<td
valign="top"></td>
<td valign="top"><input
name="Trimite" type="submit" id="Trimite" value="Modifica date">
<input name="Reseteaza" type="reset" id="Reseteaza"
value="Reseteaza"> </td>
<td></td>
</tr>
<tr>
<td height="19"></td>
<td valign="top"></td>
<td> </td>
<td></td>
</tr>
</form>
</table>';
}
break;
case
'parola':
echo '<table width="309" border="0" cellpadding="0"
cellspacing="0">
<form name="formular"
action="profil.php?actiune=validare" method="post">
<tr>
<td height="36" colspan="4" valign="top"><h1>Modifica
parola</h1></td>
</tr>
<tr>
<td width="80" height="19" valign="top"> </td>
<td
width="15" rowspan="5" valign="top"></td>
<td
width="144" valign="top"> </td>
<td width="70"
valign="top"> </td>
</tr>
<tr>
<td height="22" align="right" valign="top">Parola:</td>
<td colspan="2" valign="top">
<input
type="password" name="parola1" value=""> </td>
</tr>
<tr>
<td height="7"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="22" align="right"
valign="top">Reintroduceti parola:</td>
<td
colspan="2" valign="middle"><input type="password" name="parola2"
value=""></td>
</tr>
<tr>
<td
height="7"></td>
<td></td>
<td></td>
</tr>
<tr>
<td
height="24"> </td>
<td valign="top"></td>
<td colspan="2" valign="top"><input name="Trimite"
type="submit" id="Trimite" value="Modifica parola">
<input name="Reseteaza" type="reset" id="Reseteaza"
value="Reseteaza"> </td>
</tr>
<tr>
<td height="24"> </td>
<td
valign="top"></td>
<td> </td>
<td> </td>
</tr>
</form>
</table>';
break;
case
'validare':
if(!isset($_POST['parola1'])) $_SESSION['parola1'] =
'';
else $_SESSION['parola1'] = $_POST['parola1'];
if(!isset($_POST['parola2']))
$_SESSION['parola2'] = '';
else $_SESSION['parola2'] =
$_POST['parola2'];
if(!isset($_POST['nume'])) $_SESSION['nume'] =
'';
else $_SESSION['nume'] = $_POST['nume'];
if(!isset($_POST['prenume']))
$_SESSION['prenume'] = '';
else $_SESSION['prenume'] =
$_POST['prenume'];
if(!isset($_POST['varsta']))
$_SESSION['varsta'] = '';
else $_SESSION['varsta'] =
$_POST['varsta'];
if(!isset($_POST['localitate']))
$_SESSION['localitate'] = '';
else $_SESSION['localitate'] =
$_POST['localitate'];
if(($_POST['Trimite'] == 'Modifica date')
&& ($_SESSION['nume'] == '' || $_SESSION['prenume'] == '' ||
$_SESSION['varsta'] == '' || !is_numeric($_SESSION['varsta']) ||
strlen($_SESSION['varsta'] < 2) || $_SESSION['localitate'] == ''))
{
echo
'Completeaza campurile.<br>
Apasa <a
href="profil.php?actiune=date_personale">aici</a> pentru a te
intoarce.';
}
elseif(($_POST['Trimite'] == 'Modifica date')
&& ($_SESSION['nume'] != '' || $_SESSION['prenume'] != '' ||
$_SESSION['varsta'] != '' || is_numeric($_SESSION['varsta']) ||
strlen($_SESSION['varsta'] >= 2) || $_SESSION['localitate'] != ''))
{
echo
'Datele au fost modificate. <br>
Apasa <a
href="pagina.php">aici</a> pentru a te intoarce la pagina
principala.';
$cerereSQL = "UPDATE `utilizatori` SET
nume='".addentities($_SESSION['nume'])."',
prenume='".addentities($_SESSION['prenume'])."',
varsta='".addentities($_SESSION['varsta'])."',
localitate='".addentities($_SESSION['localitate'])."' WHERE
utilizator='".$_SESSION['user']."'";
mysql_query($cerereSQL);
$_SESSION['nume']
= '';
$_SESSION['prenume'] = '';
$_SESSION['varsta'] = '';
$_SESSION['localitate']
= '';
}
elseif(($_POST['Trimite'] == 'Modifica parola')
&& ($_SESSION['parola1'] == '' || $_SESSION['parola1'] !=
$_SESSION['parola2']))
{
echo 'Completeaza campurile.<br>
Apasa <a href="profil.php?actiune=parola">aici</a>
pentru a te intoarce.';
}
elseif(($_POST['Trimite'] == 'Modifica
parola') && ($_SESSION['parola1'] != '' || $_SESSION['parola1']
== $_SESSION['parola2']))
{
echo 'Parola a fost modificata.
<br>
Apasa <a href="pagina.php">aici</a>
pentru a te intoarce la pagina principala.';
$cerereSQL = "UPDATE
`utilizatori` SET parola='".md5($_SESSION['parola1'])."' WHERE
utilizator='".$_SESSION['user']."'";
mysql_query($cerereSQL);
$_SESSION['parola1']
= '';
$_SESSION['parola2'] = '';
}
break;
}
}
?>
Pasul
2e. Creati un fisier cu numele iesire.php si
introduceti urmatorul cod.
Cod:
- Code:
<?php
session_start();
session_destroy();
session_unset();
echo
'Ati iesit din sistem. <br>
Pentru a va intoarce la
pagina principala, apasati <a href="index.php">aici</a>';
?>
Pasul
3. Acum Intrati pe [You must be registered and logged in to see this link.] sau [You must be registered and logged in to see this link.]
Va multumesc
pentru ca ati urmarit acest tutorial
Cateva imagini
Similar topics
» [Tutorial]AWK
» Tutorial Cars
» [Tutorial]Gunz Clan
» Tutorial: Despre operatori
» [Tutorial]Intro - Concluzie
» Tutorial Cars
» [Tutorial]Gunz Clan
» Tutorial: Despre operatori
» [Tutorial]Intro - Concluzie
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Mon Feb 25, 2013 9:12 am by Guest
» Ajuta Comunitatea
Sun Feb 24, 2013 3:36 pm by Guest
» Salut de la kalean
Wed Dec 19, 2012 5:16 pm by kalean
» firecracker
Sat Oct 20, 2012 3:14 am by 10th
» Ajuta Comunitatea in dezvoltare
Wed Jul 04, 2012 5:28 pm by Guest
» welcome........
Wed Jul 04, 2012 5:25 pm by Guest
» Cerere UnBan
Mon Jul 02, 2012 5:57 pm by Guest
» Astept potentiali clienti la componente IT si cel mai bun serviciu de gazduire din Romania!
Sat Jun 30, 2012 12:54 pm by Guest
» Cerere Rank
Fri Jun 29, 2012 10:15 am by Guest