dongpao1873 2012-04-05 23:34
浏览 46
已采纳

没有数据库的php登录表单只是一个文本文件

I have the php below that works vary vary fine on localhost apache server (WAMP server) but when i put it online withowt any reason or error it doesnt do its job ! please need an answer although i will change my hosting server i dont like their services because there are many functions disabled. (update : i have a "html code" that is the profile that this code should logon-to . the profile html is after the php . this php has the problem that shows the die message even when the user and password is correct. this problem only on online server)


<?php

function password($username='noneuser') {

  $tegjitha=file_get_contents("pasetkkadmin.txt");
  $infot=preg_split('/'.PHP_EOL.'/',$tegjitha,-1,PREG_SPLIT_NO_EMPTY);
  $final=null;
  foreach ($infot as $info) {
    $pos=preg_split('/:/',$info,-1,PREG_SPLIT_NO_EMPTY);

    if ($pos[0]==$username){
      $final=$pos[1];
    }

  }
  return $final;


}


function isuser($input) {
  $tegjitha=file_get_contents("pasetkkadmin.txt");
  $infot=preg_split('/'.PHP_EOL.'/',$tegjitha,-1,PREG_SPLIT_NO_EMPTY);
  $rezultati=false;
  foreach ($infot as $info) {
    $pos=preg_split('/:/',$info,-1,PREG_SPLIT_NO_EMPTY);
    if ($input==md5('albipatozi'.$pos[0])) { $rezultati=true;}

  }
  return $rezultati;
}


if  ( isset($_GET['dil'])  ) {
  setcookie('mbajmend','',time()-3600*24*365);
  die('<meta http-equiv="REFRESH" content="0;url=index.php" />');

}

if  ( isset($_POST['username']) && !empty($_POST['username']) ) {
  $username=$_POST['username'];

} else {$username=null;}

if  ( isset($_POST['pass']) && !empty($_POST['pass']) ) {
  $passwd=sha1('justastring£"'.$_POST['pass']);


} else {$passwd='none';}

if  ( isset($_POST['mbajmend']) && !empty($_POST['mbajmend']) ) {
  $koha=time()+3600*24*60;
} else {$koha=null;}

$duhet=password($username);
if ($passwd==$duhet) { 


  setcookie('mbajmend',md5('sdaggs'.$username),$koha);


} elseif (!( isset($_COOKIE['mbajmend']) && isuser($_COOKIE['mbajmend'])  )) {


  setcookie('mbajmend','',time()-3600*24*360);
  if (isset($_SERVER['HTTP_REFERER']) &&     (preg_match('/[index.php]$/',$_SERVER['HTTP_REFERER']) ||     preg_match('/[admin\/]$/',$_SERVER['HTTP_REFERER'])) ) { $textshtes='Perdoruesi ose     Fjalkalimi jane Gabim !  '; }
  else { $textshtes='Ju Lutem Vendosni Te Dhenat Thuaja'; }

die('<body style="background:lightgrey;">
<div id="trupi" style="position:relative; background:#999999; margin:auto; width:360px;     margin-top:160px; height:260px;">
<form id="form1" name="form1" method="post" action="" style="position:absolute;     margin:56px; text-shadow:black; font-style:oblique; color:darkred">
  <label><strong>Perdoruesi:&nbsp;</strong>
  <input type="text" name="username" />
   </label>
  <p>
   <label><strong>Fjalekalimi:</strong>
   <input type="password" name="pass" />
   </label>
  </p>
  <p>
    <label>
    <input type="checkbox" name="checkbox" value="checkbox" />
    Me Mbaj Mend te Ky Kompjuter</label>
  </p>
  <p>
    <label style="float:right;">
    <input type="submit" value="Identifikohu"  />
    </label>
  </p>
  </form><p style="text-align:center; color:darkred; background:grey">    <b>'.$textshtes.'</b></p>
 </div>
 </body>

  ');

 } 

 ?>
<html>
this should be shown when user and passord is correct :)
</html>

i tried to echo every single variable one by one step by step and everything is OK exept the fact it doesnt work

the passdords txt file is pasetkkadmin.txt- its model is

superadmin:a3b22231bbe113a948a349af09cea4e4129584de

the first line is : superadmin and its password is : albi whith that data it should work but it doesnt

  • 写回答

1条回答 默认 最新

  • douwa6220 2012-04-06 01:17
    关注

    Local you use WAMP(it's windows), but online the server usually runs on a Linux-system.

    The difference is, that PHP_EOL has different values on Windows(CR+LF) and Linux(LF), so your pasetkkadmin.txt will not work like expected with the used PHP-code when you create it on windows and upload it onto a linux-server.

    Example pasetkkadmin.txt

    foo:bar[CR][LF]
    foo2:bar2
    

    On windows, splitted by PHP_EOL([CR][LF]) it will be:

    array(0=>foo:bar,
          1=>foo2:bar2)
    

    On linux, splitted by PHP_EOL([LF]) it will be:

    array(0=>foo:bar[CR],
          1=>foo2:bar2)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据