Jump to content

Recommended Posts

Hi Folks! I m kinda new to PHP. Can anyone tell me how to load different page while using index.php as page container. For example, lets say I have a page index.php and I want to load another page called contact.php in the browser.

 

In fact, I dont know how to implement the following:

 

<?php
if (!defined('WEB_ROOT')) {
exit;
}
?>
<p> </p>
<div align="center"><img src="images/headerImagefront2-final.png" alt="Header Image"></div>
<div align="center"><font color="#FFFFFF"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Home</a> | Services | About | Contact | Shipping</font></div>
<br />

<?php

if(isset($_REQUEST['page']) && !empty($_REQUEST['page'])) //CHECK WHETHER A URL VARIABLE HAS BEEN SET AND IS NOT EMPTY
{
$page=$_REQUEST['page']; //SET LOCAL VARIABLE EQUAL TO URL VARIABLE
}
else
{
$page="home"; //IF NO URL IS PASSED VIA URL THEN SET DEFAULT PAGE
}
include "other_files/" . $page; //THIS LINE WILL DISPLAY THE $page
?>

 

 

How would I add different pages to the navigation. Please help asap.

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/89663-page-linking/
Share on other sites

Well, in fact I want to load a new page but the name of that page should be used as a postfix to the address. For example, if I have an address like this:

http://site.com/index.php

 

Lets say, I have different pages, for example, info.php, contact.php, address.php. How will I implement that by adding the page names to the above address. In fact, I am looking as follow:

 

http://site.com/index.php?<what should I have to pass here in order to load other pages> 

Link to comment
https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459412
Share on other sites

Here's what I did:

 

<?php
if (!defined('WEB_ROOT')) {
exit;
}
?>
<p> </p>
<div align="center"><img src="images/headerImagefront2-final.png" alt="Header Image"></div>
<div align="center">
<a href="<?php echo $_SERVER['PHP_SELF']; ?>">Home</a> | 
<a href="http://subicca.com/index.php?page=services">Services</a> | 
<a href=""> About </a> | 
<a href="">Contact </a>| 
<a href="">Shipping</a>
</div>
<br />

<?php
if(isset($_GET['page']) && strlen($_GET['page'])>0){
    $page=$page.'.php';
    include($page);
}

?>

 

But I got this error:

 

Notice: Undefined variable: page in /home/mehreen/public_html/subicca/include/top.php on line 8

 

Warning: main(.php) [function.main]: failed to open stream: No such file or directory in /home/mehreen/public_html/subicca/include/top.php on line 9

 

Warning: main(.php) [function.main]: failed to open stream: No such file or directory in /home/mehreen/public_html/subicca/include/top.php on line 9

 

Warning: main() [function.include]: Failed opening '.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in

 

Link to comment
https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459530
Share on other sites

<?php
if ( !defined( 'WEB_ROOT' ) ) exit;
?>
<p> </p>
<div align="center"><img src="images/headerImagefront2-final.png" alt="Header Image"></div>
<div align="center">
<a href="http://subicca.com/index.php>">Home</a> | <a href="http://subicca.com/index.php?page=services">Services</a> | <a href="http://subicca.com/index.php?page=about"> About </a> | <a href="http://subicca.com/index.php?page=contact">Contact </a>| <a href="http://subicca.com/index.php?page=shipping">Shipping</a>
</div>
<br />

<?php
$home = 0;

switch ( $_GET['page'] )
{
   case services:
   include('http://subicca.com/services.php');
   break;
   case about:
   include('http://subicca.com/about.php');
   break;
   case contact:
   include('http://subicca.com/contact.php');
   break;
   case shipping:
   include('http://subicca.com/shipping.php');
   break;
   default:
   $home = 1;
   break;
}


if( $home == 1 )
{
// Code for your Homepage here... you could have just included a seperate file, within the switch statement where it says $home = 1; after "default:" but I put the code here... it will only be shown if they are NOT on the servers, about, contact or shipping page...
?>
<p>Welcome to ma webz sight.</p>
<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459599
Share on other sites

<?php
if ( !defined( 'WEB_ROOT' ) ) exit;
?>
<p> </p>
<div align="center"><img src="images/headerImagefront2-final.png" alt="Header Image"></div>
<div align="center">
<a href="http://subicca.com/index.php>">Home</a> | <a href="http://subicca.com/index.php?page=services">Services</a> | <a href="http://subicca.com/index.php?page=about"> About </a> | <a href="http://subicca.com/index.php?page=contact">Contact </a>| <a href="http://subicca.com/index.php?page=shipping">Shipping</a>
</div>
<br />

<?php
$home = 0;

switch ( $_GET['page'] )
{
   case services:
   include('http://subicca.com/services.php');
   break;
   case about:
   include('http://subicca.com/about.php');
   break;
   case contact:
   include('http://subicca.com/contact.php');
   break;
   case shipping:
   include('http://subicca.com/shipping.php');
   break;
   default:
   $home = 1;
   break;
}


if( $home == 1 )
{
// Code for your Homepage here... you could have just included a seperate file, within the switch statement where it says $home = 1; after "default:" but I put the code here... it will only be shown if they are NOT on the servers, about, contact or shipping page...
?>
<p>Welcome to ma webz sight.</p>
<?php
}
?>

 

 

Thanks, Aureole but I got the following error.

 

Home | Services |  About  | Contact | Shipping

 

 

Notice: Undefined index: page in /home/mehreen/public_html/subicca/index.php on line 29

 

Notice: Use of undefined constant services - assumed 'services' in /home/mehreen/public_html/subicca/index.php on line 31

 

Notice: Use of undefined constant about - assumed 'about' in /home/mehreen/public_html/subicca/index.php on line 34

 

Notice: Use of undefined constant contact - assumed 'contact' in /home/mehreen/public_html/subicca/index.php on line 37

 

Notice: Use of undefined constant shipping - assumed 'shipping' in /home/mehreen/public_html/subicca/index.php on line 40

 

 

BTW, here is what I have in my index.php

 

 

<?php
require_once 'library/config.php';
require_once 'library/category-functions.php';
require_once 'library/product-functions.php';
require_once 'library/cart-functions.php';

$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];

$catId  = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0;
$pdId   = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0;

require_once 'include/header.php';
?>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
<tr> 
  <td colspan="3">
  <!--?php require_once 'include/top.php'; ?>-->

<p> </p>
<div align="center"><img src="images/headerImagefront2-final.png" alt="Header Image"></div>
<div align="center">
<a href="<?php echo $_SERVER['PHP_SELF']; ?>">Home</a> | <a href="http://subicca.com/index.php?page=services">Services</a> | <a href="http://subicca.com/index.php?page=about"> About </a> | <a href="http://subicca.com/index.php?page=contact">Contact </a>| <a href="http://subicca.com/index.php?page=shipping">Shipping</a>
</div>
<br />

<?php
$home = 0;

switch ( $_REQUEST['page'] )
{
   case services:
   include('http://subicca.com/services.php');
   break;
   case about:
   include('http://subicca.com/about.php');
   break;
   case contact:
   include('http://subicca.com/contact.php');
   break;
   case shipping:
   include('http://subicca.com/shipping.php');
   break;
   default:
   $home = 1;
   break;
}


if( $home == 1 )
{
// Code for your Homepage here... you could have just included a seperate file, within the switch statement where it says $home = 1; after "default:" but I put the code here... it will only be shown if they are NOT on the servers, about, contact or shipping page...
?>
<p>Welcome to ma webz sight.</p>
<?php
}
?>
  
  </td>
</tr>
<tr valign="top"> 
  <td width="150" height="400" id="leftnav"> 
<?php
require_once 'include/leftNav.php';
?>
  </td>
  <td>
<?php
if ($pdId) {
require_once 'include/productDetail.php';
} else if ($catId) {
require_once 'include/productList.php';
} else {
require_once 'include/categoryList.php';
}
?>  
  </td>
  <td width="130" align="center"><?php require_once 'include/miniCart.php'; ?></td>
</tr>
</table>
<?php
require_once 'include/footer.php';
?>

Link to comment
https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-460164
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.