Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
Login forma

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side
View previous topic :: View next topic  
Author Message
Zeus



Joined: 09 Sep 2003
Posts: 775
Location: Čakovec

PostPosted: 14.10.2008 15:37    Post subject: Login forma Add user to your forum ignore list Reply with quote

Ovako, imam jednostavan kod:
Code:
<?php
$thepass    =    "1234";
$notlogged    =    "You need to be logged in to access this page";       
$errormsg    =    "The password provided did not work out for you"; 
$loc_action    =    "test.php";
$loc_succ    =    "test.php";
$loc_error    =    $PHP_SELF;    // The doc to go to on bad login. You can leave $PHP_SELF in most cases
$but_log    =    "Login";    // Text on the submit button

$pass        =    $_POST['pass'];
$logged        =    $_COOKIE['logged'];
$mod        =    $_POST['mod'];
// If there is no cookie and the user is not logging in, output the login form
if($logged != "1"&& $mod != "login") {
    echo '
    <b>'.$notlogged.'</b><p>
    <form name="login" action="'.$loc_action.'" method="POST">
    <input type="password" name="pass">
    <input type="hidden" name="mod" value="login">
    <input type="submit" value="'.$but_log.'">
    </form>';
    // If there is a bad login, the error message will be displayed
    if($_GET['msg'] == "err") {
        echo '<p><font color="red">'.$errormsg.'</font>';
    }
    die;
}
// if the user is logging in
elseif($logged != "1"&& $mod == "login") {
    // check the password
    if($pass == $thepass) {
        // if the pass is correct, set the cookie and go to the success page
        setcookie("logged", "1");
        header("Location: ".$loc_succ);
    } else {
        // On bad login, go back to where you came from and try it again
        header("Location:".$loc_err."?msg=err");
    }
   
}
?>


I sad ja to recimo nazovem index.php i to ucitam pri upisu domene -> upisem sifru i on me preusmjeri recimo na stranica.php. Da li postoji jednostavni nacin da se sprijeci onda ucitavanje direktno stranica.php, preko domene www.domena.hr/stranica.php
Jer onda login forma nis ne znaci Smile Mozda preko htaccess datoteke nekak?
Back to top
View user's profile Send private message Twitter profile
zytzagoo
mi3.crew


Joined: 25 Aug 2003
Posts: 1842
Location: Zagreb, Hrvatska

PostPosted: 15.10.2008 01:08    Post subject: Add user to your forum ignore list Reply with quote

U stranica.php (i ostalim na kojima zelis osigurati da je user ulogiran da bi ju vidio), koristeci
ovaj gore kôd, trebao bi provjeriti da li postoji cookie koji si setao (ili session varijabla) i da li
vrijednost spremljena u cookie (ili session) odgovara vrijednosti koju si postavio.

Ako da, prikazi stranicu, ako ne, redirect na login formu.

_________________
[+]I[+]am[+]my[+]own[+]religion[+]
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Zeus



Joined: 09 Sep 2003
Posts: 775
Location: Čakovec

PostPosted: 15.10.2008 08:06    Post subject: Add user to your forum ignore list Reply with quote

zytzagoo wrote:
U stranica.php (i ostalim na kojima zelis osigurati da je user ulogiran da bi ju vidio), koristeci
ovaj gore kôd, trebao bi provjeriti da li postoji cookie koji si setao (ili session varijabla) i da li
vrijednost spremljena u cookie (ili session) odgovara vrijednosti koju si postavio.

Ako da, prikazi stranicu, ako ne, redirect na login formu.


Hvala, upravo sam to tako jucer rijesio sa sessionima, nakon 3 sata zajebancije sa nekakvim konstantama pomocu kojih je u nekom primjeru to bilo prikazano - ali nije radilo Smile
Koliki je timeout sessiona u phpu? Googlao sam, naisao sam na podatak o 15 min, to je to?
Back to top
View user's profile Send private message Twitter profile
zytzagoo
mi3.crew


Joined: 25 Aug 2003
Posts: 1842
Location: Zagreb, Hrvatska

PostPosted: 15.10.2008 09:33    Post subject: Add user to your forum ignore list Reply with quote

Zeus wrote:
Koliki je timeout sessiona u phpu?

Koliko podesis.
http://hr.php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime

_________________
[+]I[+]am[+]my[+]own[+]religion[+]
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group