SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using php to include subpage

    I have a page that's working well in my Apache test server but not when I upload it to the hosting server. The page has includes a sub menu of images of staff, click on the image to get the bio of that person, or default to the first bio. Here's the code for the 3 files (names replaced with numbers to protect anonymity).

    bio_1.php
    Code:
    <table width="100&#37;" border="0" cellspacing="0" cellpadding="0" id="1">
    <tr><td width="70"><?php include("bio-menu_inc.php"); ?></td>
        <td><img src="images/heads_1.png" width="170" height="332"></td>
    	<td valign="top"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ligula leo, lacinia at semper vitae, tincidunt eu dui. Quisque ut nisl elit. Sed placerat mauris ac lacus sollicitudin lacinia. Donec tempor mauris tincidunt libero tincidunt a malesuada magna porta. Nam pellentesque elit lacus, vitae sodales diam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus semper leo ullamcorper elit congue et vestibulum justo commodo. </p></td></tr>
    </table>
    bio-menu_inc.php
    Code:
    <?php global $page; ?>
     <ul id="biomenu">
      <li id="bio-1"><a href="leaders.php?page=1"></a></li>
      <li id="bio-2"><a href="leaders.php?page=2"></a></li>
      <li id="bio-3"><a href="leaders.php?page=3"></a></li>
      <li id="bio-4"><a href="leaders.php?page=4"></a></li>
      <li id="bio-5"><a href="leaders.php?page=5"></a></li>
     
     </ul>
    leaders.php
    Code:
    <?php
    	if ($page=="1") {
       		include("bio_1.php");
       	} elseif ($page=="2") {
    		include("bio_2.php"); 
       	} elseif ($page=="3") {
    		include("bio_3.php");   
       	} elseif ($page=="4") {
    		include("bio_4.php");   
       	} elseif ($page=="5") {
    		include("bio_5.php");   
     	} else {
       		include("bio_1.php");
        }
    When it's "live", only the default bio shows. I tried echoing $page, in my test server it comes up but not on the host server. I tried declaring $page as global, no dice. Is the type of server (linux, unix, etc.) a consideration here? Where else can I look?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    The page value can be found in $_GET['page'].
    It works on your test server, because you have register_globals enabled. On the host server, register_globals is disabled, as it should be.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, how do I use $_GET['page'] here? I've used this method before on other servers and didn't have an issue. Registering as global was really a last ditch effort, trying all possibilities.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    bio-menu_inc.php
    Code PHP:
     <ul id="biomenu">
      <li id="bio-1"><a href="leaders.php?page=1"></a></li>
      <li id="bio-2"><a href="leaders.php?page=2"></a></li>
      <li id="bio-3"><a href="leaders.php?page=3"></a></li>
      <li id="bio-4"><a href="leaders.php?page=4"></a></li>
      <li id="bio-5"><a href="leaders.php?page=5"></a></li>
     </ul>

    leaders.php
    Code PHP:
    <?php
      $page = (int)$_GET['page']; // makes sure user input is numeric
      $filename = "bio_$page.php";
      if (!file_exists($filename)) $filename = "bio_1.php";
      include $filename;

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that did it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •