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 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败