Solved

How to include/require a page in another page

Posted on 2003-10-24
7
181 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now