首页 > 解决方案 > 将文件移动到不同文件夹后出现未定义的偏移错误

问题描述

好的,所以我有一个看起来像这样的文件夹..

loginsystem/
        homepages/
             home14.php

        includes/
             dbh.inc.php 

        header.php
        index.php

...当用户在我的网站上创建新帐户时,他们会获得一个个人主页(例如 homepages/home14)。我想在 home14.php 文件中包含我用于 index.php 文件的标头。当我尝试重新路由 home14.php 所需的位置时,我得到未定义的偏移错误。错误表明问题出在 header.php 文件的第 29 和 30 行,但它对 index.php 工作得非常好。

当我链接到 home14.php 文件中的标题时,我输入了(需要“../header.php”;)

头文件.php

<?php  
    require 'includes/dbh.inc.php';
    session_start();
    date_default_timezone_set('America/Chicago');
    include 'includes/comments.inc.php';
?>
<!DOCTYPE html>
<html>
    <head>
</head>
        <div id="headerContainer">

<!-- If the user is logged in, set username and profile picture.-->

<?php 
                if (isset($_SESSION['userID'])) {
                    $id = $_SESSION['userID'];
                    $sqlImg = "SELECT * FROM profileimg WHERE userid='$id'";
                    $resultImg = mysqli_query($conn, $sqlImg);
                    while ($rowImg = mysqli_fetch_assoc($resultImg)) {      
                        if ($rowImg['status'] == 0) {
                            $filename = "profilepics/profile".$id."*";
                            $fileinfo = glob($filename);
       -------- LINE 29 --- $fileext = explode(".", $fileinfo[0]);
       -------- LINE 30 --- $fileactualext = $fileext[1];
                            echo "<div class=userPicture><img src='profilepics/profile".$id.".".$fileactualext."?".mt_rand()."'></div>";
                        }
                        else {
                            echo "<div class='userPicture'><img src='profilepics/noUser.png'></div>";
                        }
                    }

home14.php

<?php
    require "../header.php";
    if (isset($_SESSION['userID'])) {
        echo 
            "<div class='homeBody'>



            </div>";
        require "../footer.php";    
    } 
    else {
        header("Location: ../signup.php");
        exit();
    }

?>


同样,我想要的只是在 index.php 文件中使用的相同标头,以便在 home14.php 文件中使用。当我在 home14.php 中需要它时,我只得到未定义的偏移量,而不是当我将它与 index.php 一起使用时

标签: phphtmlcss

解决方案


推荐阅读