troubleshooting Question

Passing variables: One PHP Document Within Another

Avatar of bomax
bomax asked on
PHP
8 Comments1 Solution258 ViewsLast Modified:
I have a website setup as follows: There is the main file, called index.php.  It's job is to show the html to make my page look pretty, which basically includes making up a table.  Since I have several pages within my site, I set it up so that to move to a new page the link would be like:

index.php?id=newpage.htm

What happens is index.php uses FOPEN() on 'newpage.htm', reads the contents of the file, then ECHOs the entire contents out in one of the cells of the table.  The problem here is that if I want to open up another PHP document that has a form, I can't pass variables to the second page (i.e. 'form.php').

Here is the code:

<?php

if($id) {
     $filename=$id;
     if(file_exists($filename)){
          $resource = fopen($filename,"r");
          $contents = fread($resource, filesize($filename));
          $handle = fclose($resource);
     } else {
          $contents = "Sorry!  This area of the site is currently undergoing construction but should be up shortly.  Thank you!";
     }
} else {
          $filename = "primary.htm";
          $resource = fopen($filename,"r");
          $contents = fread($resource, filesize($filename));
          $handle = fclose($resource);
}

?>

<body>
<table width="750" border="0" cellspacing="0" cellpadding="0" align=center>
  <tr>
    <td width="155" background="images/left.jpg"><img src="images/code.jpg" width="155" height="129"></td>
    <td width="595" align="left" valign="top" background="images/bluefade.jpg"><img src="images/topmenu.gif" border="0" align="baseline" usemap="#Map"></td>
***REMOVED TO SAVE SPACE***
    <td background="images/bluefade.jpg" valign=top><font size = "2" face="Arial, Helvetica, sans-serif">   ***HERE IS WHERE THE FILE IS INSERTED***   <?php printf("%s", $contents); ?></font><br><br><br></td>
  </tr>
</table>
<table width="755" border="0" cellspacing="0" cellpadding="0" align=center>
  <tr>
    <td><img src="images/bottombar.gif"></td>
  </tr>
</table>
***REMOVED TO SAVE SPACE***
</body>
</html>

How can I set it up so that I can use FOPEN to open another PHP document and have that document pass variables to itself?

Thanks,
Matt
ASKER CERTIFIED SOLUTION
Devastated

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros