Login/Logout same page
Moderatori: Zamolxe, Moderatori
Login/Logout same page
Salut!
Vreau sa gasesc un script care sa-mi permita sa vad formularul de logare cand nu sunt logat, iar cand sunt logat sa imi apara butonul logout si formularul sa dispara. Acestea sa fie pe aceeasi pagina.
Vreau sa aflu macar o sugestie.. unde sa caut.. sau cum sa fac.
Va multumesc!
Vreau sa gasesc un script care sa-mi permita sa vad formularul de logare cand nu sunt logat, iar cand sunt logat sa imi apara butonul logout si formularul sa dispara. Acestea sa fie pe aceeasi pagina.
Vreau sa aflu macar o sugestie.. unde sa caut.. sau cum sa fac.
Va multumesc!
-
- PHPRomania Supporter
- Mesaje: 27
- Membru din: Joi Mar 11, 2010 12:43 pm
- Localitate: Iasi
- Contact:
tii in sesiune daca utilizatorul este logat si faci un if
Cod: Selectaţi tot
if($_SESSION['userloged']) {
//aici userul e logat
} else {
//aici dai display la formularul de logare
}
Imi prind urechile ... ma puteti ajuta?
Acesta este codul index-ului meu:
ms:(
Acesta este codul index-ului meu:
Cod: Selectaţi tot
<?php
if(isset($_GET['bau'])) include("bau.php");
else if(isset($_GET['logdotare'])) include("logdotare.php");
else if(isset($_GET['logcomenzi'])) include("logcomenzi.php");
else if(isset($_GET['logprezentare'])) include("logprezentare.php");
else if(isset($_GET['logpolitica'])) include("logpolitica.php");
else if(isset($_GET['logdotareuk'])) include("logdotareuk.php");
else if(isset($_GET['logcomenziuk'])) include("logcomenziuk.php");
else if(isset($_GET['logprezentareuk'])) include("logprezentareuk.php");
else if(isset($_GET['logpoliticauk'])) include("logpoliticauk.php");
else if(isset($_GET['loguk'])) include("loguk.php");
else if(isset($_GET['logindex'])) include("logindex.php");
else if(isset($_GET['domain'])) include("domain_tweak.php");
require_once ( 'settings.php' );
if ( array_key_exists ( '_submit_check', $_POST ) )
{
if ( $_POST['username'] != '' && $_POST['password'] != '' )
{
$query = 'SELECT ID, Username, Active, Password FROM ' . DBPREFIX . 'users WHERE Username = ' . $db->qstr ( $_POST['username'] ) . ' AND Password = ' . $db->qstr ( md5 ( $_POST['password'] ) );
if ( $db->RecordCount ( $query ) == 1 )
{
$row = $db->getRow ( $query );
if ( $row->Active == 1 )
{
set_login_sessions ( $row->ID, $row->Password, ( $_POST['remember'] ) ? TRUE : FALSE );
header ( "Location: " . REDIRECT_AFTER_LOGIN );
}
elseif ( $row->Active == 0 ) {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link.';
}
elseif ( $row->Active == 2 ) {
$error = 'You are suspended!';
}
}
else {
$error = 'Access Denied';
}
}
else {
$error = 'Access Denied';
}
}
?>
<html>
<form id="login" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="_submit_check" value="1"/>
<fieldset>
<img src="images/username.gif" alt="username" border="0"/>
<label for="username">
<input name="username" class="input1" type="text" id="username" maxlength="30"/></label>
<span><img src="images/password.gif" alt="password" border="0"/></span>
<label for="password">
<input name="password" class="input2" type="password" id="password" maxlength="20"/>
<input name="Login" type="image" class="submit-btn" title="submit" value="Login" src="images/btn.gif" alt="submit" align="left"/></label>
<label for="register"></label>
<label for="C"><a href="register.php" class="mic">Register</a> / <a href="forgot_password.php" class="mic">Password recovery</a></label>
</fieldset>
</form>
</html>
ms:(
Cod: Selectaţi tot
//BOOL $_SESSION['este_logat'] adica poate fi true sau false
if(isset($_SESSION['este_logat']) && $_SESSION['este_logat'])
{
if(isset($_GET['logout]) && $_GET['logout'])
{
//logout
}
}
Inlocuieste codul tau cu asta :
Cod: Selectaţi tot
<?php
if(isset($_GET['bau'])) include("bau.php");
else if(isset($_GET['logdotare'])) include("logdotare.php");
else if(isset($_GET['logcomenzi'])) include("logcomenzi.php");
else if(isset($_GET['logprezentare'])) include("logprezentare.php");
else if(isset($_GET['logpolitica'])) include("logpolitica.php");
else if(isset($_GET['logdotareuk'])) include("logdotareuk.php");
else if(isset($_GET['logcomenziuk'])) include("logcomenziuk.php");
else if(isset($_GET['logprezentareuk'])) include("logprezentareuk.php");
else if(isset($_GET['logpoliticauk'])) include("logpoliticauk.php");
else if(isset($_GET['loguk'])) include("loguk.php");
else if(isset($_GET['logindex'])) include("logindex.php");
else if(isset($_GET['domain'])) include("domain_tweak.php");
require_once ( 'settings.php' );
?>
<html>
<head>
<title>Test Login</title>
</head>
<body>
<?php
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'])
{
echo ' <p>Welcome blah [<a href="#">Logout</a>]</p>';
} else if(!isset($_SERVER['logged_in']) || (isset($_SESSION['logged_in']) && !$_SESSION['logged_in'])) {
if ( array_key_exists ( '_submit_check', $_POST ) )
{
if ( $_POST['username'] != '' && $_POST['password'] != '' )
{
$query = 'SELECT ID, Username, Active, Password FROM ' . DBPREFIX . 'users WHERE Username = ' . $db->qstr ( $_POST['username'] ) . ' AND Password = ' . $db->qstr ( md5 ( $_POST['password'] ) );
if ( $db->RecordCount ( $query ) == 1 )
{
$row = $db->getRow ( $query );
if ( $row->Active == 1 )
{
set_login_sessions ( $row->ID, $row->Password, ( $_POST['remember'] ) ? TRUE : FALSE );
header ( "Location: " . REDIRECT_AFTER_LOGIN );
}
elseif ( $row->Active == 0 ) {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link.';
}
elseif ( $row->Active == 2 ) {
$error = 'You are suspended!';
}
}
else {
$error = 'Access Denied';
}
}
else {
$error = 'Access Denied';
}
}
?>
<form id="login" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="_submit_check" value="1"/>
<fieldset>
<img src="images/username.gif" alt="username" border="0"/>
<label for="username">
<input name="username" class="input1" type="text" id="username" maxlength="30"/></label>
<span><img src="images/password.gif" alt="password" border="0"/></span>
<label for="password">
<input name="password" class="input2" type="password" id="password" maxlength="20"/>
<input name="Login" type="image" class="submit-btn" title="submit" value="Login" src="images/btn.gif" alt="submit" align="left"/></label>
<label for="register"></label>
<label for="C"><a href="register.php" class="mic">Register</a> / <a href="forgot_password.php" class="mic">Password recovery</a></label>
</fieldset>
</form>
<?php
}
?>
</body>
</html>
Imi da eroarea asta:
Acum ... intrebarea mea este ... daca m-as fi logat ar fi trebuit sa se schimbe formularul pt login si sa-mi apare cel de logout, asta sa se intample in index.php
Oricum ... ms pt ajutor pana acum si sper sa pot ajunge la rezolvarea problemei
ms
Cod: Selectaţi tot
Notice: Undefined index: remember in C:\mxxCornel\site\index.php on line 57
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\mxxCornel\site\index.php:41) in C:\mxxCornel\site\functions.php on line 160
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\mxxCornel\site\index.php:41) in C:\mxxCornel\site\functions.php on line 160
Warning: Cannot modify header information - headers already sent by (output started at C:\mxxCornel\site\index.php:41) in C:\mxxCornel\site\index.php on line 58
Acum ... intrebarea mea este ... daca m-as fi logat ar fi trebuit sa se schimbe formularul pt login si sa-mi apare cel de logout, asta sa se intample in index.php
Oricum ... ms pt ajutor pana acum si sper sa pot ajunge la rezolvarea problemei
ms
Presupun ca in "settings.php" este pornite sesiunea....
Codul acesta ar trebui sa functioneze :
Sfatul meu pentru tine este sa te apuci de citit un tutorial de php pentru incepatori si sa nu incerci sa realizezi lucruri peste nivelul tau de cunostinte fara sa te documentezi riguros inainte sau fara a urma un anumit tutoriale care sa parcurga toti pasii cu tine pana iti realizezi proiectul si intelegi si ce ai facut in el...
Codul acesta ar trebui sa functioneze :
Cod: Selectaţi tot
<?php
require_once('settings.php');
if(isset($_GET['bau'])) include("bau.php");
else if(isset($_GET['logdotare'])) include("logdotare.php");
else if(isset($_GET['logcomenzi'])) include("logcomenzi.php");
else if(isset($_GET['logprezentare'])) include("logprezentare.php");
else if(isset($_GET['logpolitica'])) include("logpolitica.php");
else if(isset($_GET['logdotareuk'])) include("logdotareuk.php");
else if(isset($_GET['logcomenziuk'])) include("logcomenziuk.php");
else if(isset($_GET['logprezentareuk'])) include("logprezentareuk.php");
else if(isset($_GET['logpoliticauk'])) include("logpoliticauk.php");
else if(isset($_GET['loguk'])) include("loguk.php");
else if(isset($_GET['logindex'])) include("logindex.php");
else if(isset($_GET['domain'])) include("domain_tweak.php");
$error = '';
$logged = 0;
$submitted = 0;
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'])
{
$logged = 1;
} else if(!isset($_SERVER['logged_in']) || (isset($_SESSION['logged_in']) && !$_SESSION['logged_in'])) {
if(array_key_exists('_submit_check', $_POST))
{
$submitted = 1;
if ( $_POST['username'] != '' && $_POST['password'] != '' )
{
$query = 'SELECT ID, Username, Active, Password FROM ' . DBPREFIX . 'users WHERE Username = ' . $db->qstr ( $_POST['username'] ) . ' AND Password = ' . $db->qstr ( md5 ( $_POST['password'] ) );
if ( $db->RecordCount ( $query ) == 1 )
{
$row = $db->getRow ( $query );
if ( $row->Active == 1 )
{
set_login_sessions ( $row->ID, $row->Password, ((isset($_POST['remember'])) ? TRUE : FALSE) );
header ( "Location: " . REDIRECT_AFTER_LOGIN );
} else if ( $row->Active == 0 ) {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link.';
} else if ( $row->Active == 2 ) {
$error = 'You are suspended!';
}
} else {
$error = 'Access Denied';
}
} else {
$error = 'Access Denied';
}
}
}
?>
?>
<html>
<head>
<title>Test Login</title>
</head>
<body>
<?php
if($logged == 1)
{
echo ' <p>Welcome blah [<a href="#">Logout</a>]</p>';
} else if($logged == 0) {
if($submitted == 1 && strlen($error) > 0)
{
echo ' <p style="border : red;">'.$error.'</p>';
}
?>
<form id="login" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="_submit_check" value="1"/>
<fieldset>
<img src="images/username.gif" alt="username" border="0"/>
<label for="username">
<input name="username" class="input1" type="text" id="username" maxlength="30"/></label>
<span><img src="images/password.gif" alt="password" border="0"/></span>
<label for="password">
<input name="password" class="input2" type="password" id="password" maxlength="20"/>
<input name="Login" type="image" class="submit-btn" title="submit" value="Login" src="images/btn.gif" alt="submit" align="left"/></label>
<label for="register"></label>
<label for="C"><a href="register.php" class="mic">Register</a> / <a href="forgot_password.php" class="mic">Password recovery</a></label>
</fieldset>
</form>
<?php
}
?>
</body>
</html>
Sfatul meu pentru tine este sa te apuci de citit un tutorial de php pentru incepatori si sa nu incerci sa realizezi lucruri peste nivelul tau de cunostinte fara sa te documentezi riguros inainte sau fara a urma un anumit tutoriale care sa parcurga toti pasii cu tine pana iti realizezi proiectul si intelegi si ce ai facut in el...
Wow --- ti-ai dat interesul ... parca imi este si rusine sa mai iti scriu ... insa ... inca nu sa rezolvat problema (
Eu am index-ul asa:
Oricum ... ms si pt ajutorul de pana acum [ interesul de pana acum ]
le: desi ma loghez ... totusi imi apare regreg.php ... si nu logout
Eu am index-ul asa:
Cod: Selectaţi tot
<?php
require_once('settings.php');
if(isset($_GET['access'])) include("access.php");
else if(isset($_GET['register'])) include("register.php");
else if(isset($_GET['forgot'])) include("forgot_password.php");
else if(isset($_GET['admin'])) include("admin.php");
else if(isset($_GET['update'])) include("update_profile.php");
else if(isset($_GET['members'])) include("members.php");
else if(isset($_GET['dotare'])) include("dotare.php");
else if(isset($_GET['contact'])) include("comenzi.php");
else if(isset($_GET['prezentare'])) include("prezentare.php");
else if(isset($_GET['politica'])) include("politica.php");
else if(isset($_GET['denied'])) include("denied.php");
else if(isset($_GET['dotareuk'])) include("dotareuk.php");
else if(isset($_GET['comenziuk'])) include("comenziuk.php");
else if(isset($_GET['prezentareuk'])) include("prezentareuk.php");
else if(isset($_GET['politicauk'])) include("politicauk.php");
else if(isset($_GET['indexuk'])) include("uk.php");
else if(isset($_GET['logdotare'])) include("logdotare.php");
else if(isset($_GET['logcomenzi'])) include("logcomenzi.php");
else if(isset($_GET['logprezentare'])) include("logprezentare.php");
else if(isset($_GET['logpolitica'])) include("logpolitica.php");
else if(isset($_GET['logdotareuk'])) include("logdotareuk.php");
else if(isset($_GET['logcomenziuk'])) include("logcomenziuk.php");
else if(isset($_GET['logprezentareuk'])) include("logprezentareuk.php");
else if(isset($_GET['logpoliticauk'])) include("logpoliticauk.php");
else if(isset($_GET['loguk'])) include("loguk.php");
else if(isset($_GET['logindex'])) include("logindex.php");
else if(isset($_GET['domain'])) include("domain_tweak.php");
else if(isset($_GET['realizari'])) include("realizari.php");
else if(isset($_GET['info'])) include("info.php");
else if(isset($_GET['realizariuk'])) include("realizariuk.php");
else {
if ( isset($_REQUEST['Login']) )
{
if ( $_POST['username'] != '' && $_POST['password'] != '' )
{
$query = 'SELECT ID, Username, Active, Password FROM '.DBPREFIX.'users WHERE Username = ' . $db->qstr ( $_POST['username'] ) . ' AND Password = ' . $db->qstr ( md5 ( $_POST['password'] ) );
if ( $db->RecordCount ( $query ) == 1 )
{
$row = $db->getRow ( $query );
if ( $row->Active == 1 )
{
set_login_sessions ( $row->ID, $row->Password, ( $_POST['remember'] ) ? TRUE : FALSE );
header ( "Location: " . REDIRECT_AFTER_LOGIN );
}
elseif ( $row->Active == 0 ) {
$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link.';
}
elseif ( $row->Active == 2 ) {
$error = 'You are suspended!';
}
}
else {
$error = 'Login failed!';
}
}
else {
$error = 'Please use both your username and password to access your account';
}
} else if(isset($_GET['logout']) && $_GET['logout']) {
logout();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/base.css" />
<script type="text/javascript" src="path-to-file/jquery.js"></script>
<script type="text/javascript" src="path-to-file/thickbox.js"></script>
<style type="text/css" media="all">@import "path-to-file/thickbox.css";</style>
<link rel="stylesheet" href="path-to-file/thickbox.css" type="text/css" media="screen" />
<link rel="shortcut icon" href="favicon.gif">
</head>
<body>
<div id="container">
<div id="up">
<div id="RO/UK" style=" overflow: hidden; float: right; z-index: 1; position: absolute; right: 20px; top: 15px; width: 84px; height: 30px;">
<a href=""> <img src="images/ro1.png" alt="RO" border="0" height="20" width="41" align="left" /></a>
<a href="index.php?indexuk"> <img src="images/uk1.png" alt="UK" border="0" height="20" width="41" align="right" /></a></div>
<h1>Laborator</h1>
<p class="right">text </p>
<div id="Denied" style="overflow: hidden; position: relative; right: -40px; top: 70px;"><?php if ( isset( $error ) ) { echo ' <p class="error">' . $error . '</p>' . "\n";}?></div>
<ul>
<li><a href="index.php?contact" class="item">Contact</a></li>
<li><a href="index.php?info" class="item">Info</a></li>
<li><a href="index.php?dotare" class="item">Dotare</a></li>
<li><a href="index.php?realizari" class="item">Realizări</a></li>
<li><a href="index.php?prezentare" class="item">Prezentare</a></li>
<li><a href="index.php" class="item">Acasă</a></li>
</ul>
</div><!--up-->
<div id="content">
<div id="content_main">
<h2><A HREF="index.php" CHARSET="ISO-8859-1">site</A></h2>
<p>text</p>
<p>text</p>
<p>Stext</p>
<p> </p>
<p class="center"><img src="images/lab.jpg" width="531" height="127" border="1" /></p>
</div>
<div id="content_sub">
<?php
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'])
{
echo 'Welcome [<a href="login.php?logout=true">Logout</a>]';
} else {
include("regreg.php");
}
?>
</div>
<div id="acreditare"><h3 align="center">text</h3>
<p class="center"><img class="rec" src="images/Renar.jpg" alt="Renar" width="169" height="169"/></p>
<p class="center"><a href="album/certificat.jpg" title="Certificat Acreditare site" class="thickbox">Cetificat</a> / <a href="album/anexa.jpg" title="Anexa Acreditare site" class="thickbox">Anexa</a></p>
</div>
</div>
<div id="down">
<div id="down_main">
<p align="left"> </p>
<p align="left"><strong>asd</strong><strong><br />
asd</strong>, <strong>CK 106</strong><br />
asd <br />
<strong>Tel. </strong>asd <strong>Mob. </strong>+asd <strong>Fax. </strong>+asd </p>
<p align="left"> </p>
</div>
<div id="down_sub">
<p class="center"><a href="http://www.upb.ro/"><img class="rec" src="images/UPB1.jpg" width="50" height="50" /></a>
<a href="http://www.camis.pub.ro/"><img class="rec" src="images/tms1.jpg" width="48" height="50" /></a></p>
<p class="center"><a href="http://www.imst.pub.ro/"><img class="rec" src="images/imst1.jpg" width="97" height="50" /></a></p>
</div>
</div>
</div>
<div id="Footer">
<h4><img src="images/NDT.jpg" width="144" height="58" /></h4>
<h4>Copyright © 2010 site. Toate drepturile rezervate. Web design: Bubu.</h4>
</div>
</body>
</html>
<?php } ?>
Oricum ... ms si pt ajutorul de pana acum [ interesul de pana acum ]
le: desi ma loghez ... totusi imi apare regreg.php ... si nu logout
Da, dar eu in pagina index am si :
si ce as fi dorit e ca din index dupa ce ma logez sa ramana in index si in loc de forma pentru logare sa-mi apare logout
adica ... regreg.php - acolo este form pentru logare
insa ... desi ma loghezi ... tot regreg.php imi apare [ adica form-ul pentru logare ... ] in loc sa-mi apara echo-ul ... adica ... logout
Toate astea sa se intample pe index.php
Cod: Selectaţi tot
<?php
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'])
{
echo 'Welcome [<a href="login.php?logout=true">Logout</a>]';
} else {
include("regreg.php");
}
?>
si ce as fi dorit e ca din index dupa ce ma logez sa ramana in index si in loc de forma pentru logare sa-mi apare logout
adica ... regreg.php - acolo este form pentru logare
insa ... desi ma loghezi ... tot regreg.php imi apare [ adica form-ul pentru logare ... ] in loc sa-mi apara echo-ul ... adica ... logout
Toate astea sa se intample pe index.php
Cine este conectat
Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 37 vizitatori