douyanguo7964 2017-09-30 15:46
浏览 107
已采纳

PHP - 似乎无法重定向我的PHP文件链接到另一个文件夹中的另一个文件

i am a beginner in PHP and I am trying to learn how to make a simple registration form with mysql and php.

The problem is I cannot link to another file that is in another folder. Here are some pictures:

  1. localhost redirectory error

Even though i have placed this in my index.php codes and for other files.

<?php 
        session_start(); 

        if (!isset($_SESSION['username'])) {
            $_SESSION['msg'] = "You must log in first";
            header('location: pages/login.php');
            exit();
        }

        if (isset($_GET['logout'])) {
            session_destroy();
            unset($_SESSION['username']);

        }

    ?>

I have huge problems trying to understand how to identify the error when I include this line for a server connection in my register.php

<?php include('server.php') ?>

However it will only work if I place all the files outside of their own respective sub folders, even though I had placed the directory address. I don't understand, please help me understand what I am doing wrong.

Thank you

  • 写回答

2条回答 默认 最新

  • dt3358 2017-09-30 15:57
    关注

    To include server.php in your register page you need to use require('../server.php'). The two dots is a shortcut/alias for the parent directory.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)