tryingmybest tryingmybest - 3 years ago 152
HTML Question

PHP - Can't seem to redirect my php files to link to another file that is in another folder

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download