Autor Zpráva
sisel
Profil *
Mám knihu ku ktorej sú pridané na stránka cpressu kódy.Lenže server na ktorom som nepodporuje kódy php3 a tak vás prosím či by mi niekto nevedel dať kód login.php v PHP5.S funkciou SESSION. Prosím dáte mi kód.
Ďakujem
fandaa
Profil
Což takhle napsat o kterou knížku jde? Doporučuji spíše koupit novou knížku v PHP5.
IMHO ti tady moc lidí nebude přepisovat tvůj kód podle tvého přání.
peta
Profil
sisel
Kod do php5 neni problem udelat, pokud by byl kod z php3. Nastesti jsi nic takove nenabidl, takze se problem vyresil a je mozne to tu zamknout. :)

Priklad jednoducheho loginu s overovanim vuci databazi v oracle.

<?php
// === USER authorize ===
session_start();

if (!isset($SQL_query)) {$SQL_query = array();}
$SQL_query['user_role'] = "
SELECT * FROM id_table2 WHERE id_name = 'AAA' AND aktivni = 'A'
";

$a = 'user_name'; $_SESSION[$a] = strToUpper( isset($_POST[$a]) ? $_POST[$a] : (isset($_SESSION[$a]) ? $_SESSION[$a] : '') );
$a = 'user_psw'; $_SESSION[$a] = strToUpper( isset($_POST[$a]) ? $_POST[$a] : (isset($_SESSION[$a]) ? $_SESSION[$a] : '') );

$user_name = $_SESSION['user_name'];
$user_psw = $_SESSION['user_psw'];
$user_role = ''; //role = none
$user_logged = 0;
$db_conn0 = @ocilogon($user_name,$user_psw,$db);
$db_conn = ocilogon($CFG_SQLuser,$CFG_SQLpsw,$db); //prihlaseni na uzivatele xyz/xyz, protoze vidi dane tabulky
if (!$db_conn0)
{ //neni v databazi
}
else
{
oci_close($db_conn0);
// student, admin
$user_logged = 1;
$user_role = 'ST'; //role = student
$query = $SQL_query['user_role'];
$query = str_replace('AAA',$user_name,$query);
$res_all = fce_sq($query);

if (count($res_all)>0 && isset($res_all[0]['ID_ROLE']))
{$user_role = $res_all[0]['ID_ROLE'];}
}

// user logout
if (isset($_GET['logout']) && $_GET['logout']==1)
{
session_unset();
$user_name = '';
$user_psw = '';
$user_role = ''; //role = none
$user_logged = 0;
}

$home = '<a href="http://home.page.cz"><img src="ico_home.gif" width="32" height="36" border="0"/></a>';


function form_userlogin($url,$hidden = array())
{
global $home;
$t = '';
if (count($hidden)>0)
{
foreach ($hidden as $key=>$value)
{$t.= "\n".'<input type="hidden" name="'.$key.'" value="'.$value.'"/>';}
}
return '
<form name="form_userlogin" action="'.$url.'" method="post">'.$t.'
<table>
<tr>
<th rowspan="4">'.$home.'</th>
<th><label for="user_name">Uľiv. jmeno (os. číslo)</label></th>
<th><label for="user_psw" >Heslo</label></th>
<th><br/></th>
</tr>
<tr>
<td><input type="text" name="user_name" id="user_name" value=""/></td>
<td><input type="password" name="user_psw" id="user_psw" value=""/></td>
<td><input type="submit" value="Přihlásit"/><td>
</tr>
</table>
<hr/>
</form>
';
}

function form_userlogout($url)
{
global $SESSION;
global $home;
return '
<form name="form_userlogout" action="'.$url.'" method="get">
<input type="hidden" name="logout" value="1"/>
<table>
<tr>
<th>'.$home.'</th>
<td>Uzivatel: <b>'.$_SESSION['user_name'].'</b><td>
<td><input type="submit" value="Odhlásit"/><td>
</tr>
</table>
<hr/>
</form>
';
}


Pouziti
<?php
$CFG_file = "tento_soubor.php"; //this file name
include_once("config_inc.php");
include_once("login_inc.php");

$url = $CFG_file;
if (!$user_logged) {echo form_userlogin($url);}
else {echo form_userlogout($url);}
?>

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0