This is my first post here so apologies if the setup is kind of scrambled.
I am in the middle of working on an article database with MySQL and PHP.
I have a page which will show all articles by authors. I am trying to have a link at the top of the page redirect with a few PHP if statements so the user will have to log in if not already. If the user is already logged in (I haven’t a PHP script for adding users to database yet, working on it) the redirect will load a form to submit a new article.
Controller (index.php) :
<?php
include_once $_SERVER['DOCUMENT_ROOT'] .
'/includes/magicquotes.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] .
'/includes/access.inc.php';
if (isset($_GET['add']))
if (!userIsLoggedIn())
{
include '/Test/articles/login.html.php';
exit();
}
else
{
include 'form.html.php';
exit();
}
:::PHP code left out for sake of example:::
include 'articles.html.php';
?>
access.inc.php contains SESSION() and $sql enrty scripts for entering and retaining username/passwords
userIsLoggedIn() is a function in access.inc.php (self explanatory)
login.html.php is my login form
form.html.php is the actual form to submit new articles
articles.html.php is the page which displays all of the articles in my database
My problem is that when I implement the if statement for the link to redirect to my login form when the user has not already logged in, I get PHP warnings when clicked which I don’t get because my paths are correct for /Test/articles/login.html.php and I’m unsure what to do about it.
Warnings :
Warning: include(/Test/articles/login.html.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\Test\articles\index.php on line 10
Warning: include() [function.include]: Failed opening '/Test/articles/login.html.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Test\articles\index.php on line 10
Help please? I’m at a total loss.
$_SERVER['DOCUMENT_ROOT']is almost never a good choice when it comes to determining folder structure because its unreliable.Use
dirname(__FILE__)instead.BTW, your real mistake was that you included a slash before Test (
/Test/...) indicating that you want to access a folder residing on a root level of the web server.