dpmrakfbx820320638 2017-12-26 04:55
浏览 62

splfileobject不能使用php7.0在ubuntu 16.04 apache webserver上工作

I have been making a website that has a user-account-loggin system that is based on accessing .txt files in php. I originally tested much of the code on a free web-hosting service and got the user-account-loggin system functional, but when I tried to move it over to my own personal apache web server the functionality of some of my php code seems to have been lost and I'm not sure why. Specifically, I have narrowed it down to the splfileobject() function returning no value for the variable $passfile. Am I missing some php library that is necessary to do this? When I looked it, up it said that php7.0 had splfileobject(), and its other connected functions, as part of the standard php library.

Here is some of my code

<?php
$username = $_POST["username"];
$password = $_POST["password"];

$account = file('usernames.txt');
$accountfix = str_replace("
", "", $account);
$filepoint = array_search($username, $accountfix);

if ($filepoint !== false) {

    $passfile = new SplFileObject('passwords.txt', 'r+');

    $passfile->seek($filepoint);

    $potentialpass = str_replace("
", "", $passfile);

// check password
if ($password === $potentialpass) {
$_SESSION["username"] = $username;
$_SESSION["password"] = $password;
$_SESSION["loggedin"] = true;
$_SESSION["filepoint"] = $filepoint;
print "Logged in succesfully!";
}
else{
    print "Incorrect Password";
}
}
else {
 print "Incorrect Username.";
}

?>

For some reason opening a file like this works fine.

$account = file('textfiles/usernames.txt');

However, I want to be able to search to a specific point in a password file the has parallel data to the username file to cut down on computation time and had to use splfileobject to do so.

Thankyou

  • 写回答

1条回答 默认 最新

  • drr7731 2017-12-27 20:07
    关注

    I fixed the problem, apparently The web server needed to be given permission to read and write on .txt files. I never received any errors regarding this. I was able to give it permission to do so with the following commands into the linux terminal.

    sudo chown -R www-data /var/www
    sudo chmod -R u=rwx /var/www
    

    Many thanks to beno1990 at ubuntuforums.org Heres the thread I found it on, https://ubuntuforums.org/showthread.php?t=1089334

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测