Help - Search - Members - Calendar
Full Version: Php Navigation
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Colin
A while ago I used Zymic's tutorial on php nav but since itsnot in this version I can't use it ...I found a different tutorial and here it the code I am using:
<?php
switch($_GET['page']) {
default: include('content/home.php');
break;
case "home": include('content/home.php');
break;
}
?>
When I define a page (index.php?page=home) it works fine when I don't it gives me this error code:
Notice: Undefined index: page in /www/zymichost.com/c/o/l/colin... on line 42
and it still displays my content but with that code there too...here is my page without defining
http://colin.zymichost.com/index.php
with defining:
http://colin.zymichost.com/index.php?page=home
What am I doing wrong? Thanks - Colin
Jacobxx
Its a problem with Zymic's PHP Configuration... If no one posts a fix by tomorrow then I will when Iget a chance to try it. Its late. Just know its not your code -- its zymic.
Zytran
QUOTE(Colin @ Sep 19 2007, 03:12 AM) *
A while ago I used Zymic's tutorial on php nav but since itsnot in this version I can't use it ...I found a different tutorial and here it the code I am using:
<?php
switch($_GET['page']) {
default: include('content/home.php');
break;
case "home": include('content/home.php');
break;
}
?>
When I define a page (index.php?page=home) it works fine when I don't it gives me this error code:
Notice: Undefined index: page in /www/zymichost.com/c/o/l/colin... on line 42
and it still displays my content but with that code there too...here is my page without defining
http://colin.zymichost.com/index.php
with defining:
http://colin.zymichost.com/index.php?page=home
What am I doing wrong? Thanks - Colin

Suppress the warning at _GET and check if empty.
CODE
    $page = @$_GET['page'];
    if(empty($page))
    {
        $page = 'home';
    }
    else {
        $page = $_GET['page'];
    }
    switch($page)
    {
        default:
            include('content/home.php');
        break;
        case "home":
            include('content/home.php');
        break;
    }
Mark
We'll suppress the notices ASAP.
Colin
QUOTE(Zytran @ Sep 19 2007, 04:22 AM) *
Suppress the warning at _GET and check if empty.
CODE
    $page = @$_GET['page'];
    if(empty($page))
    {
        $page = 'home';
    }
    else {
        $page = $_GET['page'];
    }
    switch($page)
    {
        default:
            include('content/home.php');
        break;
        case "home":
            include('content/home.php');
        break;
    }

Thanks...worked
xangelo
I suggest
CODE
addslashes(strip_tags($_GET['page']))
instead of using the $_GET['page'] exactly how it is.
Alex
We don't need to sanitise the variable, because we're not outputting it at any point, only throwing it into a switch. If you were, then you might want to htmlspecialchars() it or some such, but in the context he's using it in, that is unnecessary overhead - especially since there's no reason to make ?page=<b>home</b> work. If someone is messing around with the links that's their problem.
Enom
It's much easyer to do this:
CODE
<?
if($_GET['page'] == "principal") {require "content/home.php";}
elseif($_GET['page'] == "tabela") {require "content/anotherpage.php";}
else {require "content/home.php";}
?>
Ed
QUOTE(Enom @ Sep 29 2007, 01:40 PM) *
It's much easyer to do this:
CODE
<?
if($_GET['page'] == "principal") {require "content/home.php";}
elseif($_GET['page'] == "tabela") {require "content/anotherpage.php";}
else {require "content/home.php";}
?>


A switch is so much cleaner.
shinjiketojapann
Try the fallowing

CODE
<?PHP

$path = ".";

elseif($act == "page1"){ include("$path/somepagehere.php"); }
elseif($act == "random"){ echo"Some random text here";
/* include("$path/main.php"); */ }
else{ include("$path/main.php"); }

?>


use this if you have a search(add to the top of the script,INSIDE THE PHP LINES)

CODE
if($do == "search" or $dosearch == "yes"){ $subaction = "search"; $dosearch = "yes";
include("$path/search.php"); }


to change the location of the included "HOME" info/news change this line

CODE
else{ include("$path/main.php"); }


change main.php to like idn news.php whatever is needed

to have a user go to the page included into your main page use the fallowing html line(edit as needed)

CODE
<a href="act=page1">page</a>


and do add/edit pages
you can use 2 diff. things
the first

CODE
elseif($act == "page1"){ include("$path/somepagehere.php"); }

this will include an external page you can change the "act" and "page1" to something elts for the new page

the the second one

CODE
elseif($act == "random"){ echo"Some random text here";

as above you can change the "act" and "random" to something elts to identify the page and for the echo part change as needed as well,i find it to be a good copyright page,only because you cant use html in this echo.

just add more of both for new pages.
i also find it easy to separate everything by category or whatever you have but using the fallowing.

CODE
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  some text here
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */


as my final note:
Don't tell me it needs some changes or something ok it works why should it matter?

please PM or something if this helped,I don't check the forum often.
Nexus
I have a question - what's this PHP Navigation do, exactly?
Sek_Death
does the php vav help you..for when you update a top link thats displayed globaly itll automatically update the rest of the links on everypage... (like an image too)

if not can some 1 tell me a script that can do that because im desperate for one of those!!!
shinjiketojapann
QUOTE(Sek_Death @ Oct 4 2007, 03:52 AM) *
does the php vav help you..for when you update a top link thats displayed globaly itll automatically update the rest of the links on everypage... (like an image too)

if not can some 1 tell me a script that can do that because im desperate for one of those!!!
this site has 1 index page and all other content can be updated via the included page so yes
http://shinjiketojapan.cogia.net
Sek_Death
one moe question were do i put the code 0_o sorry its that i tryed once before but it didnt work T____T
shinjiketojapann
QUOTE(Sek_Death @ Oct 5 2007, 01:03 AM) *
one moe question were do i put the code 0_o sorry its that i tryed once before but it didnt work T____T

here i will provide the source of that index page and you can learn from that ok?
good.

this file in in a .php formate

CODE
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

    <link rel="shortcut icon" href="favicon.ico" >

    <link rel="icon" href="animated_favicon1.gif" type="image/gif" >

<?PHP
include "var.php";

$path = ".";
$title = "ShinjiketoJapan";
$descritpion = "Japanese lovers UNITE!!";
$meta = "japanese,shinjiketo,japan,miyavi,dir en grey,j-rock,j-pop";

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  This is a fix if register_globals is turned off
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
if(!$PHP_SELF){
    if($HTTP_POST_VARS)     {extract($HTTP_POST_VARS, EXTR_PREFIX_SAME, "post_");}
    if($HTTP_GET_VARS)      {extract($HTTP_GET_VARS, EXTR_PREFIX_SAME, "get_");}
    if($HTTP_COOKIE_VARS)    {extract($HTTP_COOKIE_VARS, EXTR_PREFIX_SAME, "cookie_");}
    if($HTTP_ENV_VARS)         {extract($HTTP_ENV_VARS, EXTR_PREFIX_SAME, "env_");}
}
if($PHP_SELF == ""){ $PHP_SELF = $HTTP_SERVER_VARS[PHP_SELF]; }

?>

<head>

    <title>ShinjiketoJapan</title>

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

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

</head>

<body>

<div id="content">

<h1 title="Site design by Andrew Sullivan AKA akira"></h1>

<ul id="top">

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

<li><a href="./forums/index.php">Forums</a></li>

<li><a href="?about=me">About</a></li>

<li><a href="?contact=me">Contact Us</a></li>

</ul>

<div id="banner">
<script type="text/javascript" language="JavaScript">

Ban = new Array("./lib/banner1.png","./lib/banner2.jpeg")
BDS = Ban.length
PAGE = "./"
WIDTH = "800"
HEIGHT = "140"

if (document.images) {
R = Math.floor((Math.random() * BDS))
document.write("<a href='"+PAGE+"'><img src='"+Ban[R] +"' width='"+WIDTH+"' height='"+HEIGHT+"' /></a>");
}
</script>

</div>

<div id="left">

<h2>Main Navigation</h2>

<ul>

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

<li><a href="?about=me">About</a></li>

<li><a href="?contact=me">Contact Us</a></li>

<li><a href="./forums/index.php">Forums</a></li>

</ul>

<h2>Links</h2>

<ul>

<li><a href="?vids=index">Videos</a></li>

<li><a href="?act=blog">Blog</a></li>

<li><a href="http://shinjiketojapan.cogia.net/forum/album.php">Gallery</a></li>

<li><a href="?act=donate">Donate(on/off)</a></li>

<li><a href="?act=affiliate">Affiliates</a></li>

<li><a href="">Link 6</a></li>

</ul>

<h2>search</h2>

<form method="post">
<td width="100%" align="center">&nbsp;<br>
<input type="text" name="story" size="15">
<input type="hidden" name="do" value="search">
<input type="submit" value="Search">
</td>
</form>

</div>


<div id="right">

<h2>Main Navigation</h2>

<ul>

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

<li><a href="?about=me">About</a></li>

<li><a href="?contact=me">Contact Us</a></li>

<li><a href="./forums/index.php">Forums</a></li>

</ul>
<h2>Ads/Feeds</h2>
<a title="RSS Feed" href="http://shinjiketojapan.cogia.net/news/rss.php?category=2">
<img src="http://shinjiketojapan.cogia.net/news/skins/images/rss_icon.gif" border=0  />
</a><BR>
<a href="?act=advertise"><img src="lib/wantad.gif" alt="" /></a>
</div>



<div id="main">

<h2>News/Pages</h2>


<blockquote>

The site is not fully working,but im working on it.

</blockquote>


<?PHP

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Here we decide what page to include
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

if($do == "search" or $dosearch == "yes"){ $subaction = "search"; $dosearch = "yes";
include("$path/news/search.php"); }
elseif($act == "affiliate"){ include("$path/forum/aff.php"); }
/* begin of vids */
elseif($vids == "index"){ include("$path/vids.php"); }
/* begin of miyavi */
elseif($vids == "Jibun1Kakumei"){ include("$path/vids/miyavi1Jibun1Kakumei.php"); }
elseif($vids == "roadJack"){ include("$path/vids/roadJack.php"); }
elseif($vids == "kukuru"){ include("$path/vids/miyavikukuru.php"); }
/* end of miyavi */
/* begin of mell */
elseif($vids == "redfaction"){ include("$path/vids/mellredfaction.php"); }
/* begin of mell */
/* begin of dir en grey */
elseif($vids == "kickthecan"){ include("$path/vids/direngreykickthecan.php"); }
/* end of dir en grey */
elseif($vids == "seventeen"){ include("$path/vids/ladytron1seventeen.php"); }
/* end of vids */
elseif($act == "pics"){ include("$path/pictures.php"); }
elseif($act == "blog"){ include("$path/blog.php"); }
elseif($contact == "me"){ include("$path/contact.php"); }
elseif($about == "me"){ include("$path/about.php"); }
elseif($act == "donate"){ include("$path/donate.php"); }
elseif($act == "404"){ include("$path/404.php"); }
elseif($act == "advertise"){ include("$path/advertise.php"); }
elseif($act == "copy"){ echo"ShinjiketoJapan is owned,and run by Andrew sullivan,all vids pictures and other copyrighted images/video are owned by the peaple they describe. &copy; 2006-2007";
/* include("$path/main.php"); */ }
else{ include("$path/news.php"); }

?>



<p class="posted"><a href=""></a></p>



<div id="copyright">

Copyright &copy; 2006-2007 <a href="?act=copy">shinjiketoJapan</a><br />
<a href="java script:window.location.reload()">Click to reload!</a><br />
<script LANGUAGE="JavaScript">
var x= new Date();
document.write (x);
</SCRIPT>
</div>



</div>

</div>

</body>

</html>
Ed
shinjiketojapann, I did a bit of googling and discovered the following snippet appears in cutenews:

CODE
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  This is a fix if register_globals is turned off
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
if(!$PHP_SELF){
    if($HTTP_POST_VARS)     {extract($HTTP_POST_VARS, EXTR_PREFIX_SAME, "post_");}
    if($HTTP_GET_VARS)      {extract($HTTP_GET_VARS, EXTR_PREFIX_SAME, "get_");}
    if($HTTP_COOKIE_VARS)    {extract($HTTP_COOKIE_VARS, EXTR_PREFIX_SAME, "cookie_");}
    if($HTTP_ENV_VARS)         {extract($HTTP_ENV_VARS, EXTR_PREFIX_SAME, "env_");}
}
if($PHP_SELF == ""){ $PHP_SELF = $HTTP_SERVER_VARS[PHP_SELF]; }


Why are you using it? I can only assume it is a hack because the CuteNews programmers didn't want to change hundreds of variables abusing 'register_globals', the register_globals feature is an unnecessary evil, so using their hack seems somewhat fruitless. Unless you are actually using some sort of cutenews engine, then might I suggest converting your spoofed registered globals to their respective super global counterparts $_GET, $_POST, $_COOKIE and $_SERVER.

Its unnecessary overhead to be assigning all those values to new variables on every script run, the variables are already assigned in another variable. Your '$do' is $_GET['do'], so yeah.

I remember a few years back when CuteNews abused 'extract', it passed the entire $HTTP_POST_VARS array into it, by just posting a form with the same field names the same as variables in the script, you could override most things, can't remember the exact script but one executed shell commands, well that was of course brought around an exploit to remotely execute arbitrary shell commands on the site's server. Nice to see that they actually use a prefix for duplicates now.

Fun times.
shinjiketojapann
im using that for something elts in my wrappers but i dont use cutenews
Sek_Death
o0o0o0o ko0ol thnxs =D
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.