Solved

How to include/require a page in another page

Posted on 2003-10-24
7
187 Views
Last Modified: 2011-09-20
I'm trying to include this page below:
http://gryphon.murdoch.edu.au/~group13/kalamunda/displayarticle.php?area=front

into this page here:
http://gryphon.murdoch.edu.au/~group13/kalamunda/test.php
.. so i used...
<?php
include ('http://gryphon.murdoch.edu.au/~group13/kalamunda/displayarticle.php?area=front');
?>

(1) Is there a way not to include the full path and let it auto detect?
(2) When i click on link which is in the include page. the url becomes test.php?id=1
instead of displayarticle.php?id=1

is there a way to fix it to link to displayarticle.php instead of test.php?
0
Comment
Question by:sivil
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
DoppyNL earned 43 total points
ID: 9612553
you can also include files relative to the current location.
Downside is that you won't be able to use parameters after ?
Upside is that you can use the global variables in the script.


regarding (2):
Make sure that the script that outputs those links, links to displayarticle.php, and not to something else.
0
 
LVL 2

Assisted Solution

by:ramonklown
ramonklown earned 41 total points
ID: 9614035
Hey

There are 2 possibilities one is you can link to another page and send out a header
Example the link is
http://gryphon.murdoch.edu.au/~group13/kalamunda/displayarticle2.php
and inside that page there is a header going to
http://gryphon.murdoch.edu.au/~group13/kalamunda/displayarticle.php?area=front

instead of include you can user require... which is a little better when thinking about security risks.... (after all it's never secure anyways)

Post the "link code" so we can see what is your problem there.... of just post the hole page to see what is going on with the posting os linking...
0
 
LVL 2

Expert Comment

by:ramonklown
ID: 9614041
forgot to post the link to header section http://www.php.net/header
0
 
LVL 11

Assisted Solution

by:shmert
shmert earned 41 total points
ID: 9615303
There's an important thing to note when you include() a file with a full URL.   PHP is sending a new request out to the webserver to get that file.  This is most definitely not the most efficient way to do this.

I'd recommend creating a third php file for generating article HTML, which is never called directly from the webserver.  This third file is shared by both your test.php and displayarticle.php pages.  Then you can use include() with relative paths to get to this third page, and reuse the code.

Example contents of files:

# test.php
<html>
<head><title>this is a test page</title></head>
<body>
<?php
$areaToDisplay = 'front';
include ('_article.php');
?>
</body>
</html>

# displayarticle.php
<html>
<head><title>Showing exciting article stuff</title></head>
<body>
<?php
$areaToDisplay = $_REQUEST['area'];
include ('_article.php');
?>
</body>
</html>

# _article.php
# this does the fetching and generating of the article
if (!isset($areaToDisplay)) die ("You must specify an area to display");
// output article here...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
website maintenance mode 1 25
Logic behind "best rated" calculation 11 31
php56-php-mcrypt for rhel7 php56 1 50
Wordpress Query 5 25
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question