pages in index.php

Example of PHP code.

Moderator: Moderators

pages in index.php

Postby MarioFireGamer on Wed Feb 08, 2006 3:36 pm

'ello, uh, just thought I'd share this, I did this on my site to organize stuff.

You can create cases for like
index.php?page=pagename
And the code below will say whatever page is, to look for the case, and require what case pagename has.
I'm not making any sense.

Code: Select all
<?php
// Set page to any kind of variable you want to replace page in index.php?page=pagename
if(isset($HTTP_GET_VARS['page']))
// Be sure that if you change the page field in the first line to change it here in the $p area as well
{
$p = $HTTP_GET_VARS['page'];
}
// This says that if index.php has no value to get a home page included, but address bar still contains index.php
else
{
$p = 'index';
}

switch($p)
// Below is case index, where the $p='index'; looks for a home page. We can tell it for the homepage to look for home.php
{
case 'index':
require('home.php');
break;

// Here you can insert more and as many as you want require cases. Archives do not run here with &file=
case 'news':
require('news.php');
break;

// You can also make redirects manually instead of using an include redirect, see the code in my reply post for how to do so
case 'phpbbstyles':
require('phpbbstyles.php');
break;

// All require pages must end in .php
case 'anything you want':
require('mypage.php');
break;

// The error message if a required page will not come up or a bad variable is given see my 3rd reply for more info
default:
exit('Error 404');
}

?>
MarioFireGamer
banned
banned
 
Posts: 359
Joined: Tue Dec 13, 2005 2:21 pm

Redirect for the phpbbstyles.php page

Postby MarioFireGamer on Wed Feb 08, 2006 3:40 pm

Please do not copy paste the code from above also, you should download the code to a .txt file first or it will not align properly and cause remarks to run as commands and fail the code.

PHP Redirect

For our phpbbstyles.php that we had above we can make a manual redirect by inserting this code into phpbbstyles.php:

Note: For starters, the title feature is not needed since a title bar won't be used except for on dialup connections with slow redir.
Code: Select all
<?php
// After Location we want the redirect url for phpbbstyles.php or whatever file to make a PHP Redirect
header("Location: http://www.phpbbstyles.com/");
// The below exit tag is very important or phpbbstyles.com would be included in your index.php file we made wayyyy above
exit();
?>


Again, download the .txt code before copypasting.

[ edit :]
the title feature would break redirection as the result would be "Cannot modify header information. Header output started at ..." or similar so deleted html stuff that was before <?php
- baz-x
MarioFireGamer
banned
banned
 
Posts: 359
Joined: Tue Dec 13, 2005 2:21 pm

Error in inclusion customization page

Postby MarioFireGamer on Wed Feb 08, 2006 3:43 pm

If you have a 404 page customized, you can use a JAVASCRIPT redirect to do this but not a php redirect or the two codes will crash and index.php? will not work at all.

Code: Select all
default:
// Inside the Script code you can change the variable redirphpurl to the 404 page it should NOT be relative to the web
exit('<script language=javascript>var redirphpurl=\"http://yoursite.com/404.html\" document.location=redirphpurl</script>');
MarioFireGamer
banned
banned
 
Posts: 359
Joined: Tue Dec 13, 2005 2:21 pm


Return to PHP Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest