2012-04-05 33 views
0

我有以下的php工作變化本地主機apache服務器(WAMP服務器)上的不同罰款,但是當我把它放在網上withowt任何原因或錯誤它does not做它的工作!請需要一個答案,雖然我會改變我的託管服務器,我不喜歡他們的服務,因爲有許多功能被禁用。 (更新:我有一個「html代碼」,這是該代碼應該登錄的配置文件。配置文件html是在php之後。這個php有問題,即使用戶和密碼正確時也顯示死信息。這個問題只在網上服務器php登錄表單沒有數據庫只是一個文本文件


<?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> 

我想一步一步,一切都呼應每一個變量的一個上是exept的事實確定它不工作

的passdords TXT文件pasetkkadmin.txt- 其型號是

超級管理員:a3b22231bbe113a948a349af09cea4e4129584de

,第一行是:超級管理員,密碼爲:阿爾比 蒙山數據它應該工作,但它不

+1

篩選代碼非常困難;你知道縮進嗎?您可以縮進代碼塊以使其更具可讀性。另外,你有什麼特別的錯誤?你有沒有做過任何調試嘗試? – Ryan 2012-04-05 23:37:26

+0

是的,我做了,但沒有錯誤rezultet。 (順便說一下,我的電腦上的代碼是在塊中,但在這裏我不適合使用代碼所需的4個空格,所以當我複製粘貼它時,我有點搞砸了) – 2012-04-05 23:41:31

+0

「does not ['] t do its工作」; 「does not't work」 - 什麼_specifically_不起作用? (我們不應該問!) – halfer 2012-04-05 23:54:25

回答

2

本地使用WAMP(它的窗口),但網上的服務器通常在Linux系統上運行。

區別在於,PHP_EOL在Windows(CR + LF)和Linux(LF)上具有不同的值,所以當您在Windows上創建並使用PHP代碼時,您的pasetkkadmin.txt不能像預期的那樣使用PHP代碼它到一個linux服務器上。

例pasetkkadmin.txt

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

在Windows中,通過PHP_EOL([CR][LF])分裂這將是:

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

在Linux中,通過PHP_EOL([LF])分裂這將是:

array(0=>foo:bar[CR], 
     1=>foo2:bar2) 
+0

的方式很好的添加,但是從密碼返回的字符串與密碼相同,並且我的代碼問題仍然存在:$ duhet = password($ username); if($ passwd == $ duhet){//放入cookie}。即使$ passwd與$ duhet相同,服務器不會返回true語句($ passwd == $ duhet)!你能解釋一下嗎?!因爲我對這段代碼感到無聊。 (所以它不是一個操作系統差異問題) – 2012-04-06 01:23:05

+0

wehe!你有權利,我只是測試它,我所要做的就是以某種方式修剪該字符串,並解決了我的情況。我感謝不同。 – 2012-04-06 01:38:04

相關問題