2012-05-20 54 views
0

这是我的第一个php脚本。我实际上在vb.net编码..我为.net应用程序制作此许可系统。这个许可系统有一个管理员,管理员可以轻松控制和查看。另外Iam正在做一个类库来登录和注册。我只使用vb.net代码成功地完成了这项工作,但由于证书需要存储在应用程序中,所以始终存在威胁。舌头:用这个问题可以克服一些:。所以我决定使用这种有点PHP脚本来制作登录+注册系统。我正在使用一个唯一的管理读取,写入文本文件,而不是一个MySQL数据库(所有托管服务轻松maneagable)。所以,我想出了以下这段代码,在确认登录部分时需要一些帮助。 文本文件是这样的:PHP - 读取ftp文本文件并提取所需数据

用户名密码HWID lastdate membershiptype

所有通过“空间”和每行一个账户分开。 我希望我已经提供了足够的信息,如果需要额外的信息,我会给它。

<?php 
$user = addslashes($_GET['username']); 
$pass = addslashes($_GET['password']); 

    $username = "theusername"; 
    $password = "thepassword"; 
    $url = "mywebsite.com/file.txt"; 
    $hostname= "ftp://$username:[email protected]$url"; 
    $contents = file_get_contents($hostname); 
// That gives me the txt file which can only be read and written by the admin 
if (strpos($contents,$user) !== false) { 
    // Need code here to check if the adjacent word and the $pass are same to establish a successfull login 
} else { 
echo "Username does not exist, please register" 
} 
?> 
+1

你能具体谈谈你的问题? – jedwards

+0

空格和段落是你的朋友。 – jmort253

+0

他想遍历文件并获取每行的值来比较信息。 – rcdmk

回答

1

这里试试这个,希望它有助于:

file.txt的需要砥这种格式,通过:分隔值,空间是不是单独的值的好方法。

username:password:hwid:lastdate:membershiptype 

的PHP位:

<?php 
$user = $_GET['username']; 
$pass = $_GET['password']; 

if(check_auth(get_auth(),$user,$pass)==true){ 
    echo 'Yes'; 
}else{ 
    echo 'No'; 
} 

/** 
* This function will grab the text file and create a user array 
* 
* @return array(0=>username,1=>password) 
*/ 
function get_auth(){ 
    $username = "theusername"; 
    $password = "thepassword"; 
    $url = "mywebsite.com/file.txt"; 
    $location = "ftp://$username:[email protected]$url"; 

    $users = file($location); 
    function split_auth(&$value){ 
     $value = explode(':',$value); 
    } 
    array_walk($users,'split_auth'); 
    return $users; 
} 

/** 
* This Function will check the username and password 
* against the users array 
* 
* @param array $users 
* @param string $username 
* @param string $password 
* @return bool (true|false) 
*/ 
function check_auth($users,$username,$password){ 
    foreach($users as $user){ 
     if($user[0]==$username && $user[1]==$password){ 
      return true; 
     } 
    } 
    return false; 
} 
?> 
+0

那么这将工作?用户名:密码:hwid:lastdate:membershiptype – HooCraX

+0

是的,如果你更改'用户名密码hwid lastdate membershiptype'到'用户名:密码:hwid:lastdate:membershiptype' –

+0

像一个魅力工程谢谢曼=) – HooCraX