shak123 Posted February 6, 2008 Share Posted February 6, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/ Share on other sites More sharing options...
tinker Posted February 6, 2008 Share Posted February 6, 2008 i'm not sure if you want to redirect to the other page using header, or open a file and output the contents or to use the mod_rewrite module where the server rewrites the URL? Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459410 Share on other sites More sharing options...
shak123 Posted February 6, 2008 Author Share Posted February 6, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459412 Share on other sites More sharing options...
rameshfaj Posted February 6, 2008 Share Posted February 6, 2008 You can import or include the desired page or use header() function in the very first of the index.php.This can also be done in the META tag of the index.php to redirect to the desired page. Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459458 Share on other sites More sharing options...
shak123 Posted February 6, 2008 Author Share Posted February 6, 2008 Yea, thats what i m looking for and how? Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459474 Share on other sites More sharing options...
rameshfaj Posted February 6, 2008 Share Posted February 6, 2008 Using header() u can do like this: in index.php page include this line: ... header("Location:http://jobspokhara.com.np"); ... then u will be redirected to the above mentioned url. Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459479 Share on other sites More sharing options...
Stooney Posted February 6, 2008 Share Posted February 6, 2008 http://site.com/index.php?page=info if(isset($_GET['page']) && strlen($_GET['page'])>0){ $page=$page.'.php'; include($page); } Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459480 Share on other sites More sharing options...
shak123 Posted February 6, 2008 Author Share Posted February 6, 2008 http://site.com/index.php?page=info if(isset($_GET['page']) && strlen($_GET['page'])>0){ $page=$page.'.php'; include($page); } Will I add the above code in a href tag? What if I have more then page, how will i include them and make my navigation? Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459485 Share on other sites More sharing options...
shak123 Posted February 6, 2008 Author Share Posted February 6, 2008 Any other help, plz? Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459518 Share on other sites More sharing options...
Stooney Posted February 6, 2008 Share Posted February 6, 2008 yea, so <a href="http://site.com/index.php?page=info">INFO</a> Then somewhere in index.php: if(isset($_GET['page']) && strlen($_GET['page'])>0){ $page=$page.'.php'; include($page); } Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459519 Share on other sites More sharing options...
shak123 Posted February 6, 2008 Author Share Posted February 6, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459530 Share on other sites More sharing options...
Aureole Posted February 6, 2008 Share Posted February 6, 2008 <?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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-459599 Share on other sites More sharing options...
shak123 Posted February 6, 2008 Author Share Posted February 6, 2008 <?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'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-460164 Share on other sites More sharing options...
Aureole Posted February 8, 2008 Share Posted February 8, 2008 Put " ' " around the things, e.g. case 'services': Quote Link to comment https://forums.phpfreaks.com/topic/89663-page-linking/#findComment-461470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.