473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

include won't work for some reason

Hey all, I'm trying to get this include to work but I can't for some
reason. Each file I'm trying to include is named articles.php, but the
directories are different. So I set up the link to my include.php file
like this

<a href="include.php?directory='.$articlename.'">'.$a rticletitle.'</a>

and on the reciving end

<?php include '/'.$_GET["directory"].'/articles.php'; ?>

The rest of the page comes up, but the incuded part is nowhere to be
found.

I'd appreciate any help anyone could offer.

Thanks,
RC.

Oct 6 '06 #1
4 1406
Forgot to mention, the hyperlink is in php, and when I change include
to echo it comes out as it should:

/content/articles.php

Oct 6 '06 #2
ro********@gmail.com wrote:
<?php include '/'.$_GET["directory"].'/articles.php'; ?>
The include file is fetched from the file system.
You are trying to fetch /<QUERYSTRING_DIRECTORY>/articles.php
----------------------- ^

You can either omit the '/' (and make sure the QUERYSTRING_DIRECTORY
exists as a subdirectory of the one the script is running from) or
specify the full path to the articles.php script(s).

<?php
$article_dir = $_GET['directory'];

### You will need to write the `directory_is_valid()` function :)
if (directory_is_valid($article_dir)) {
include 'C:/Apache/htdocs/' . $_GET["directory"] . '/articles.php';
} else {
### For simplicity sake, just exit with an error message
exit('Invalid directory.');
}
?>

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Oct 7 '06 #3
ro********@gmail.com wrote:
Hey all, I'm trying to get this include to work but I can't for some
reason. Each file I'm trying to include is named articles.php, but the
directories are different. So I set up the link to my include.php file
like this

<a href="include.php?directory='.$articlename.'">'.$a rticletitle.'</a>

and on the reciving end

<?php include '/'.$_GET["directory"].'/articles.php'; ?>

The rest of the page comes up, but the incuded part is nowhere to be
found.

I'd appreciate any help anyone could offer.

Thanks,
RC.
What exactly does $articlename contain?

Also, the way you're accessing it is relative to the root of the file
system. If you want it relative to the root of the webserver, you need
to use:

<?php include $_SERVER['DOCUMENT_ROOT'] .
'/'.$_GET["directory"].'/articles.php'; ?>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 7 '06 #4
>Hey all, I'm trying to get this include to work but I can't for some
>reason. Each file I'm trying to include is named articles.php, but the
directories are different. So I set up the link to my include.php file
like this

<a href="include.php?directory='.$articlename.'">'.$a rticletitle.'</a>

and on the reciving end

<?php include '/'.$_GET["directory"].'/articles.php'; ?>
Using include on a variable file name with unchecked user-supplied
pieces is very dangerous, especially if it is possible for a user to
put any files on the system in question or if the filename can be
made remote. It's a great way to inject viruses.

Oct 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jez | last post by:
I'm ashamed that I need to ask this question. I've been using PHP for almost a year now, and have used HTML extensively in the last few years. Often, when I create a new site, I use include() to...
22
by: Martin MOKREJ© | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
7
by: mescaline | last post by:
Hi, Suppose a_file.cpp contains a function a_function() Now to include it in main_file.cpp I just do #include "a_file.cpp" and I'm all set. i recently came across this seemingly roundabout...
3
by: Rick | last post by:
Is it possible to include a file from another server in html? I have typed <!-- #include file="http://Nlg-info/PESE/PESE.asp" --> is this the correct code? I cannot have the files together as...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
6
by: Goran | last post by:
Hi all, this is just a "design" question. I'm unsure where to put my "#includes". Should I put it directly into headerfiles? Or into sourcefiles with a forward type declaration in...
25
by: Mark | last post by:
so, i'm making a website. let's say i have header.php, footer.php and content.php. now in index.php I simply want to include the 3 pages. easy enough to do. but let's say the user navigates to...
6
djsjm
by: djsjm | last post by:
Hi guys! I may be overlooking something dumb here... For a series of subdirectories I put the masthead in as an include file, with ../ up to the directory above it. Problem is, it won't pull...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.