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
nakon logina prazna stranica

 
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
nel`chee



Joined: 08 Jul 2004
Posts: 2087
Location: Rijeka

PostPosted: 27.12.2005 22:22    Post subject: nakon logina prazna stranica Add user to your forum ignore list Reply with quote

Code:
include 'form_auth.php';
   if (form_authenticate() !== true) die();
   // all checked, ok.

nakon ovoga ide sadrzaj. medjutim, dobijem bijelu stranicu i moram refreshat i onda je sve ok. zasto i kako?

_________________
art & design portfoliofree Photoshop brushes stuffsketchblogfacebook
Back to top
View user's profile Send private message Visit poster's website Twitter profile
lekke



Joined: 17 Jun 2004
Posts: 860
Location: 25th floor

PostPosted: 27.12.2005 22:41    Post subject: Add user to your forum ignore list Reply with quote

if (form_authenticate() !== true) die();

_________________
You need more bass.
Back to top
View user's profile Send private message
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 27.12.2005 23:53    Post subject: Add user to your forum ignore list Reply with quote

Lekke, pa ako funkcija vraća bool onda nema veze jesu dva znaka li jedan.

A ti nam Nel'chee nisi dala dovoljno informacija. Samo vidovnjak može iz jednog include-a i jednog poziva funkcije shvatiti što se tu dešava Surprised

Last edited by Sulien on 28.12.2005 00:02; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nel`chee



Joined: 08 Jul 2004
Posts: 2087
Location: Rijeka

PostPosted: 27.12.2005 23:55    Post subject: Add user to your forum ignore list Reply with quote

i kad maknem to isto je.
poanta je sto kad refresham sve bude u redu i dalje je sve okej, samo taj prvi put kad se ulogiram dodje prazno.
ovaj if se poziva svaki put.

ocete cijeli form_auth.php ? ima toga dosta

_________________
art & design portfoliofree Photoshop brushes stuffsketchblogfacebook
Back to top
View user's profile Send private message Visit poster's website Twitter profile
nel`chee



Joined: 08 Jul 2004
Posts: 2087
Location: Rijeka

PostPosted: 27.12.2005 23:57    Post subject: Add user to your forum ignore list Reply with quote

Code:
<?php
function get_key () {
   global $HTTP_COOKIE_VARS;
   if (isset($HTTP_COOKIE_VARS['AUTHKEY'])) {
      return $HTTP_COOKIE_VARS['AUTHKEY'];
   }
   return false;
}
function generate_key($userid) {
   $secret = 'nekatajnarijec';
   $user_key = md5($userid);
   $checksum = md5 ($user_key . $secret);
   $skey = $user_key . ',' . $checksum;
   return $skey;
}
function store_key($key, $userid) {
   setcookie('AUTHKEY', $key, time() + 3600);
   $keyfile = '../tmp/authkey_' . $key;
   if(file_exists($keyfile)) return false;
   $fp = fopen($keyfile, 'w');
   if (!(fwrite($fp, $userid)))
      return false;
   fclose ($fp);
   return true;
}
function ckeck_key($key) {
   $secret = 'nekatajnarijec';
   list($user_key, $checksum) = explode(',', $key);
   if(md5($user_key . $secret) != $checksum)
      return false;
   $keyfile = '../tmp/authkey_' . $key;
   if(!(file_exists($keyfile)))
      return false;
   return true;
}
function show_auth_form ($err='')
{
   global $HTTP_POST_VARS;
   $tmpl = <<<EOT
<!DOCTYPE html
   PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="hr" lang="hr">
<head>
<title>Login</title>
<link rel="Stylesheet" type="text/css" href="../racunalstvo.css" />
</head>
<body>
<form action="%s" method="post">
   <div style="text-align: center">
   <h1>Log in</h1>
   <span style="color: red">%s</span><br />
   <table class="login">
   <tr><td>Username</td><td><input class="textfield" type="text" name="u" size="15" value="" /></td></tr>
   <tr><td>Password</td><td><input class="textfield" type="password" name="p" size="15" value="" /></td></tr>
   <tr><td></td><td><input type="submit" value="Enter" class="button" /></td></tr>
   </table>
   </div>
</form>
</body>
</html>
EOT;
   $page = @sprintf($tmpl, $GLOBALS['PHP_SELF'], $err);
   echo $page;
}
function authorize_user ($user, $pass)
{
   include 'config.php';
   if ($user !== $username) {
      write_log($user, $pass, 0);
      return false;
   }
   if ($pass !== $password) {
      write_log($user, $pass, 0);
      return false;
   }
   return true;
}
function write_log($user, $pass, $sucess) {
   $log = '../news/login.log';
   if ($sucess==1) $entry = "Login: $user [".$_SERVER['REMOTE_ADDR']."] logged in at: ".date("Y/m/d H:i:s");
      else $entry = "Error: $user [".$_SERVER['REMOTE_ADDR']."] tried to log in with password $pass at: ".date("Y/m/d H:i:s");
   if (file_exists($log)) {
         $file = fopen($log, 'ab');
         fwrite($file, "\n$entry", strlen("\n$entry"));
         fclose($file);
      } else {
         $file = fopen($log, 'ab');
         fwrite($file, $entry, strlen($entry));
         fclose($file);
         chmod($log, 0666);
      }
}
function form_authenticate () {
   global $HTTP_POST_VARS;
   $skey = get_key(); // cheking the key
   if($skey !== false) {
      if (ckeck_key($skey)) {
         return true;
      }
   }
   if (count($HTTP_POST_VARS) == 0) {
      show_auth_form();
      return false;
   } else {
      $user = $HTTP_POST_VARS['u'];
      $pass = $HTTP_POST_VARS['p'];
      if(empty($pass) || empty($pass)) {
         show_auth_form('Please enter your username and password');
         return false;
      }
      if (authorize_user($user, $pass) !== true) {
         show_auth_form('Login failed, please try again.');
         return false;
      }
   }
   write_log($user, $pass, 1);
   if(!(store_key(generate_key($user), $user))) {
      return false;
   }
   return true;
}
?>

_________________
art & design portfoliofree Photoshop brushes stuffsketchblogfacebook
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 28.12.2005 00:13    Post subject: Add user to your forum ignore list Reply with quote

Uh... ružno do bola. A da rađe koristiš session? Iskreno nije mi ni dalje jasno što refresh napravi da stvar prođe... imaš log funkciju, iskoristi je za debugging.

Ova skripta loše emulira rad sessiona i pola njene funkcionalnosti sasvim je bespotrebna
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nel`chee



Joined: 08 Jul 2004
Posts: 2087
Location: Rijeka

PostPosted: 28.12.2005 00:18    Post subject: Add user to your forum ignore list Reply with quote

nah, nvm. nemam sad vremena.

_________________
art & design portfoliofree Photoshop brushes stuffsketchblogfacebook
Back to top
View user's profile Send private message Visit poster's website Twitter profile
lekke



Joined: 17 Jun 2004
Posts: 860
Location: 25th floor

PostPosted: 28.12.2005 08:14    Post subject: Add user to your forum ignore list Reply with quote

Sulien wrote:
Lekke, pa ako funkcija vraća bool onda nema veze jesu dva znaka li jedan.

A ti nam Nel'chee nisi dala dovoljno informacija. Samo vidovnjak može iz jednog include-a i jednog poziva funkcije shvatiti što se tu dešava Surprised


Stvarno ne znam ima li veze ili ne, ali mi se cinilo da koristenje "!==" invertira ponasanje if uvjeta - "bijela stranica" nije nista drugo nego die() bez parametara. A koliko vidim, tih "!==" ima jos ohoho po kodu. No... vidio sam tu neke tablice pa sam prestao gledat Very Happy

_________________
You need more bass.
Back to top
View user's profile Send private message
retro_one



Joined: 16 Sep 2003
Posts: 880
Location: DUBRAVA.

PostPosted: 28.12.2005 10:19    Post subject: Add user to your forum ignore list Reply with quote

!== provjerava uz vrijednost i tip varijable.

@nelchee: zast koristis $HTTP_POST_VARS umjesto $_POST?

_________________
Just your average eccentric programmer.
Back to top
View user's profile Send private message
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 28.12.2005 12:46    Post subject: Add user to your forum ignore list Reply with quote

lekke wrote:
Stvarno ne znam ima li veze ili ne, ali mi se cinilo da koristenje "!==" invertira ponasanje if uvjeta

Pa da. To je u stvari užasno loš način da se napiše
Code:
if(!form_authenticate()) die();


Meni se ne čini da je ovo Nel'chee napisala, barem ne po HTML markupu. Prvu polovicu koda sigurno nije.

A vidi ovo
Code:
if(empty($pass) || empty($pass))

i ovo
Code:
if ($sucess==1)


ovo već liči na Nel'chee
Code:
chmod($log, 0666);

i ovo Smile
Code:
fopen($log, 'ab');


Arrow http://php.linux.hr/session Exclamation
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nel`chee



Joined: 08 Jul 2004
Posts: 2087
Location: Rijeka

PostPosted: 28.12.2005 17:17    Post subject: Add user to your forum ignore list Reply with quote

Sulien wrote:
Meni se ne čini da je ovo Nel'chee napisala, barem ne po HTML markupu. Prvu polovicu koda sigurno nije.

tu si u pravu Smile

Quote:
ovo već liči na Nel'chee
Code:
chmod($log, 0666);

i ovo Smile
Code:
fopen($log, 'ab');

tocno, taj log feature sam dodala Smile (i damn da idem maknut binary Embarassed )

damn Sulien, "poznas me po kodu" Laughing

me go check

_________________
art & design portfoliofree Photoshop brushes stuffsketchblogfacebook
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