PDA

View Full Version : Right, you will help me.



today
23-07-2008, 05:32 PM
(:

Whats the best navigation system to use..

Links to tutorials if can, or something :]]

Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks :).

Janczyk
23-07-2008, 05:33 PM
Something that involves php includes but preferably not the nav?=community.php or whatever. Oh, and not AJAX either.

today
23-07-2008, 06:46 PM
help help help bump.

Stepheen
23-07-2008, 06:53 PM
No idea what your looking for but I think what you want is something like this (http://dynamicdrive.com/dynamicindex1/switchmenu.htm)?

Janczyk
23-07-2008, 06:55 PM
No, a way of navigation.

Stepheen
23-07-2008, 07:00 PM
No, a way of navigation.
Oh,
I'd use iframes if I had a radio or something like that on my site.
If you're site is rather ajax'ee then have the ajax thing (I've completely forgot what it's called!)
PHP includes for anything else :)

Janczyk
23-07-2008, 07:01 PM
PHP incldues ins't a way of navigation.

iframes - just lol.

I said I don't want AJAX.

loserWILL
23-07-2008, 07:07 PM
I like to use something like:

PHP

<?php

if($_GET['?page=home']{
echo home;
}

?>

HTML:


<a href="?page=home">Home</a>

Though there are many different methods that accomplish the same thing.

today
23-07-2008, 07:08 PM
Well a good version which is safe. :]

Janczyk
23-07-2008, 07:14 PM
I would like it targetted if possible.

--ss--
23-07-2008, 07:27 PM
In the div you will have your content in, insert the following PHP code:


<?php
$page = $_GET['p'];
if(!isset($page))
{
include("main.php");
}
elseif(file_exists("". $page . ".php"))
{
include("" . $page . ".php");
}
else
{
print("The page <b>" . $page . ".php</b> does not exist.");
}
?>

Create a page called main.php and insert all you default introduction text which will be shown if a page isn't selected.
You're links will look like:


<a href="index.php?p=about">About</a>
<a href="index.php?p=news">News</a>
<a href="index.php?p=staff">Staff</a>

And so on.
(Create an .php file for each one though with the content within it).

For an customized error page you would replace

print("The page <b>" . $page . ".php</b> does not exist.");
with

include("exist.php");
with the exist.php file contained your customized error page to be shown ;).

today
23-07-2008, 07:52 PM
can it not be /home/news/article5?

--ss--
23-07-2008, 07:58 PM
can it not be /home/news/article5?

That's what htacess is for lol ;).

today
23-07-2008, 08:00 PM
Erm i cant code to save ma life mate lol.

Janczyk
27-07-2008, 10:05 AM
Sorry to bump this but Shane, is this targetted?

/me is noob at PHP.

CoolHostUK-Dom
27-07-2008, 10:24 AM
Shane, yours is a bit insecure isnt it? (not 2 sure though).

If you wanted to use like /news/article/5

http://www.workingwith.me.uk/articles/scripting/mod_rewrite =]

Protege
27-07-2008, 11:25 AM
In the div you will have your content in, insert the following PHP code:


<?php
$page = $_GET['p'];
if(!isset($page))
{
include("main.php");
}
elseif(file_exists("". $page . ".php"))
{
include("" . $page . ".php");
}
else
{
print("The page <b>" . $page . ".php</b> does not exist.");
}
?>
Create a page called main.php and insert all you default introduction text which will be shown if a page isn't selected.
You're links will look like:


<a href="index.php?p=about">About</a>
<a href="index.php?p=news">News</a>
<a href="index.php?p=staff">Staff</a>
And so on.
(Create an .php file for each one though with the content within it).

For an customized error page you would replace

print("The page <b>" . $page . ".php</b> does not exist.");with

include("exist.php");with the exist.php file contained your customized error page to be shown ;).

Could tidy up the php a bit man lol, i'd use an array to show what pages are allowed to be access etc.


<?php
$pages = array ( 'homepage' => 'pages/home.php',
'news' => 'pages/news.php',
'god' => 'pages/godjames.php'
);

if ( $pages[ $_GET[ 'page' ] ] != '' )
{
include_once ( $pages[ $_GET[ 'page' ] ] );
}
elseif ( $_GET[ 'page' ] == '' )
{
include_once ( $pages[ 'homepage' ] );
}
else
{
echo ( 'Sorry, that page doesn\'t exist' );
}
?>

haven't really tested it, but its a basic outline etc.

--ss--
27-07-2008, 12:37 PM
Sorry to bump this but Shane, is this targetted?

/me is noob at PHP.
What do you mean?

Could tidy up the php a bit man lol, i'd use an array to show what pages are allowed to be access etc.


<?php
$pages = array ( 'homepage' => 'pages/home.php',
'news' => 'pages/news.php',
'god' => 'pages/godjames.php'
);

if ( $pages[ $_GET[ 'page' ] ] != '' )
{
include_once ( $pages[ $_GET[ 'page' ] ] );
}
elseif ( $_GET[ 'page' ] == '' )
{
include_once ( $pages[ 'homepage' ] );
}
else
{
echo ( 'Sorry, that page doesn\'t exist' );
}
?>haven't really tested it, but its a basic outline etc.
Your way is far more secure and efficient but it's quite annoying having to keep updating everytime you make a new page lol :(.

Protege
27-07-2008, 12:38 PM
Better to be safe than sorry though :P

Janczyk
27-07-2008, 12:40 PM
I'm in agreement about making a new page and is the one you did Shane secure enough?

I mean as in, you load say about.php inside the main div that you put that code in?

Would I have to copy index.php again into about.php or just the content and that content will load up in the main div?

Sorry if I haven't explained very well.

Protege
27-07-2008, 12:42 PM
The one Shane did is secure enough I believe

Calon
27-07-2008, 12:42 PM
I'd do this; but you being able to add the content via a different page, but included on the $_GET.



<?php
$_GET['navigation'];

switch ($_GET['navigation']):
case "home":
include "home.php";
break;
case "contact":
include "contact.php";
break;
case "freeporn":
include "freeporn.php";
break;
default:
echo "You did not enter a valid page name into the navigation URL.";
endswitch;
?>

--ss--
27-07-2008, 01:15 PM
The code I posted should be safe seeing as I originally discovered it on ask.com or one of the other professional PHP wiki sites :P

I'm presuming your div coding looks something like this currently?


<div id="container">
<div id="banner"></div>
<div id="mid">
<div id="left">
<div id="box">
Dummy text
</div>
<div id="nav">
<!-- Nav links -->
Link
Link
Link
Link
Link
<!-- End Nav -->
</div>
</div>
<div id="right">
<div id="content">
<!-- Welcome message -->
Welcome to Site.com , blah blah blah.
<!-- End message -->
</div>
</div>
</div>
<div id="footer"></div>
</div>

You'd take out the welcome message and put that into the file called main.php which will be shown automatically. You will put the PHP code inside the welcome message comments , where your text previously was.
You then replace the nav links with the news ones so you should end up with it being:

<div id="container">
<div id="banner"></div>
<div id="mid">
<div id="left">
<div id="box">
Dummy text
</div>
<div id="nav">
<!-- Nav links -->
<a href="index.php?p=about">About</a>
<a href="index.php?p=news">News</a>
<a href="index.php?p=staff">Staff</a>
<!-- End Nav -->
</div>
</div>
<div id="right">
<div id="content">
<!-- Welcome message -->
<?php
$page = $_GET['p'];
if(!isset($page))
{
include("main.php");
}
elseif(file_exists("". $page . ".php"))
{
include("" . $page . ".php");
}
else
{
print("The page <b>" . $page . ".php</b> does not exist.");
}
?>
<!-- End message -->
</div>
</div>
</div>
<div id="footer"></div>
</div>

Quite hard to explain :(

Janczyk
27-07-2008, 01:26 PM
I'll try;

I have a navigation, latest news, updates and a seperate box on the left and a content box on the right. In the content box I place this code and it will show main.php upon load of the site. I then click the relevant tab on the navigation say, about and it brings up about.php in the content box only but still loads the div's on the left?

--ss--
27-07-2008, 01:30 PM
I'll try;

I have a navigation, latest news, updates and a seperate box on the left and a content box on the right. In the content box I place this code and it will show main.php upon load of the site. I then click the relevant tab on the navigation say, about and it brings up about.php in the content box only but still loads the div's on the left?
Yep, nothing will change other than the div the php is in, that div will load the content for you ;).

Janczyk
27-07-2008, 01:33 PM
That's what I wanted to know :P

Thanks Legend.

Invent
27-07-2008, 01:40 PM
<?php

$page = $_GET[ "page" ]; // Change this for whatever you want the word after "?" be. (EG, using "page" you will do "?page=blah").

$args = array( ".", "http", "www", "/", "\\" ); // This stops people from getting files in other directories.
$page = str_replace( $args, "", $page );

if( isset( $page ) && trim( $page ) != "" )
{

include( $page . '.php' );

}
elseif( !isset( $page ) && trim( $page ) == "" )
{

include( "main.php" ); // This is the page that will be shown if you don't specify to load another page.

}
else
{

include( "404.php" ); // This is the page that will be shown if the page specified to load doesn't exist.

}

?>
Just another method :P

Calon
27-07-2008, 01:45 PM
The code I posted should be safe seeing as I originally discovered it on ask.com or one of the other professional PHP wiki sites :P

I'm presuming your div coding looks something like this currently?


<div id="container">
<div id="banner"></div>
<div id="mid">
<div id="left">
<div id="box">
Dummy text
</div>
<div id="nav">
<!-- Nav links -->
Link
Link
Link
Link
Link
<!-- End Nav -->
</div>
</div>
<div id="right">
<div id="content">
<!-- Welcome message -->
Welcome to Site.com , blah blah blah.
<!-- End message -->
</div>
</div>
</div>
<div id="footer"></div>
</div>You'd take out the welcome message and put that into the file called main.php which will be shown automatically. You will put the PHP code inside the welcome message comments , where your text previously was.
You then replace the nav links with the news ones so you should end up with it being:

<div id="container">
<div id="banner"></div>
<div id="mid">
<div id="left">
<div id="box">
Dummy text
</div>
<div id="nav">
<!-- Nav links -->
<a href="index.php?p=about">About</a>
<a href="index.php?p=news">News</a>
<a href="index.php?p=staff">Staff</a>
<!-- End Nav -->
</div>
</div>
<div id="right">
<div id="content">
<!-- Welcome message -->
<?php
$page = $_GET['p'];
if(!isset($page))
{
include("main.php");
}
elseif(file_exists("". $page . ".php"))
{
include("" . $page . ".php");
}
else
{
print("The page <b>" . $page . ".php</b> does not exist.");
}
?>
<!-- End message -->
</div>
</div>
</div>
<div id="footer"></div>
</div>Quite hard to explain :(
Switch case things are better than IF statements, as simon taught me in another thread.

Invent
27-07-2008, 01:48 PM
Switch case things are better than IF statements, as simon taught me in another thread.

Only in certain circumstances ;)

--ss--
27-07-2008, 01:52 PM
<?php

$page = $_GET[ "page" ]; // Change this for whatever you want the word after "?" be. (EG, using "page" you will do "?page=blah").

$args = array( ".", "http", "www", "/", "\\" ); // This stops people from getting files in other directories.
$page = str_replace( $args, "", $page );

if( isset( $page ) && trim( $page ) != "" )
{

include( $page . '.php' );

{
elseif( !isset( $page ) && trim( $page ) == "" )
{

include( "main.php" ); // This is the page that will be shown if you don't specify to load another page.

}
else
{

include( "404.php" ); // This is the page that will be shown if the page specified to load doesn't exist.

}

?>
Just another method :P
You're just extra :P

Switch case things are better than IF statements, as simon taught me in another thread.
Nope they're not, it depends on what you're trying to with them. Lets say you have a large site with around 60 pages, it's not like you're going to make a case for each page and keep adding new ones each time when you can simply let the PHP automatically find the page for you. But if you were to do something simple like having a GD library image form with like 3 or 4 options then switches would do the job better.

Trigs
27-07-2008, 02:53 PM
<?php

$page = $_GET[ "page" ]; // Change this for whatever you want the word after "?" be. (EG, using "page" you will do "?page=blah").

$args = array( ".", "http", "www", "/", "\\" ); // This stops people from getting files in other directories.
$page = str_replace( $args, "", $page );

if( isset( $page ) && trim( $page ) != "" )
{

include( $page . '.php' );

{
elseif( !isset( $page ) && trim( $page ) == "" )
{

include( "main.php" ); // This is the page that will be shown if you don't specify to load another page.

}
else
{

include( "404.php" ); // This is the page that will be shown if the page specified to load doesn't exist.

}

?>


Just another method :P

You typo'd it I think...
After include( $page . '.php' ); you put another opening bracket. Shouldn't it be a closing?

Invent
27-07-2008, 05:18 PM
Yeah, thanks.
Fixed my post (:

Want to hide these adverts? Register an account for free!