Solved

How to include/require a page in another page

Posted on 2003-10-24
7
183 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 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…

919 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

22 Experts available now in Live!

Get 1:1 Help Now