Jump to content

Index.php?page=whatever


Recommended Posts

For a thing that seems to be so common in websites i have had alot of trouble in trying to find the code on how to do it. I Have done it before but forget how to do it.

www.mysite.com/index.php?page=whatever...

I need to have that plus when nothing is after page= have it goto home.html

Thanks for your help

Link to comment
Share on other sites

depends, but for a simple example, lets assume you have this:

index.php

header.php

navbar.php

body.php

footer.php

and you have these pages you want included in the body:

home.html

about.html

links.html

contact.html

 

you would do this in the body.php

<?php
$good_links = array("home", "about", "links", "contact");
if (isset($_GET['page'])){
if (in_array($_GET['page'], $good_links)){
	include($_GET['page'].".html");
}
else{
	include("home.html");
}
}
else{
include("home.html");
}
?>

Link to comment
Share on other sites

hey ok i will add little bit more for you :P

 

ok creat a folder called include...

then add in it file you would like to include so

main.php

forum.php

shout.php

me.php ect ect

 

then on you index.php or where ever add this

 

<? $page = $_GET['page'];
                    if (ereg('[A-Za-z0-9]',$page) ) {
                        if (file_exists('include/'.$page.'.php')) {
                            include('include/'.$page.'.php');
                        } else {
                            include('include/main.php');
                        }
                   } else {
                            include('include/main.php');
                    }?>

 

so then your link would be www.mysite.com/index.php?page=me  bang you have me.php show :P

Link to comment
Share on other sites

Will that still apply if i dont have everything seperated into body.php nav.php  and just have the whole design in the index.php and paste that code into the place where i want the content to go

 

include() executes the referenced file as if it were part of the script calling include().  Or in other words, when PHP encounters include(), it opens and executes the file and any output from that file gets dumped into the calling script where the include() statement was encountered.

 

So the short answer is, "Yes, that should work."

Link to comment
Share on other sites

it came up with this error

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1512;}\viewkind4\uc1\pard\f0\fs20 HOme\par } �

hOme is what i had typed in the home.php file

 

Dont know whats up

i appricitate you guys helping and your quick replys

 

Link to comment
Share on other sites

<html xmlns="http://www.w3.org/1999/xhtml">

<head><script language="JavaScript">

 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>\</title>

<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="wrapper">

  <div id="content">

    <div id="header">

      <div id="logo">

        <h1>logo here</h1>

        <h4>have your punchline here</h4>

      </div>

      <div id="links">

        <ul>

          <li><a href="#">Home</a></li>

          <li><a href="#">Projects</a></li>

          <li><a href="#">Tutorials</a></li>

          <li><a href="#">Forum</a></li>

   

        </ul>

      </div>

    </div>

    <div id="mainimg">

    </div>

    <div id="contentarea">

      <div id="leftbar">

        <h2>hello!</h2>

      <? $page = $_GET['page'];

                    if (ereg('[A-Za-z0-9]',$page) ) {

                        if (file_exists('include/'.$page.'.php')) {

                            include('include/'.$page.'.php');

                        } else {

                            include('include/home.php');

                        }

                  } else {

                            include('include/home.php');

                    }?>

        <br />

      </div>

      <div id="rightbar">

        <h2>latest news</h2>

        <p><span class="orangetext"><?php

$tpath = "/home/redneckt/public_html/news/";

$lim = "5";

$page = "/index.php";

include($tpath . "headlines.php");

?></ span> </p>

      </div>

    </div>

    <div id="bottom">

      <div id="email"><a href="mailto:admin@rednecktc.com">Admin@rednecktc.com</a></div>

      <div id="validtext">

        <p>Valid <a href="http://validator.w3.org/check?uri=referer">XHTML</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a></p>

      </div>

    </div>

  </div>

</div>

</body>

</html>

Link to comment
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.