Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to include/require a page in another page

Posted on 2003-10-24
7
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
DoppyNL earned 172 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 164 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 164 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

704 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