Jump to content

Clean URLs,


Miley CYrus

Recommended Posts

<?php// change "id" to what ever you want index.php?id=contact > contact.php

  $nav = $_GET['id'];

 

 

                switch ($nav) {

 

 

              Case "contact"; //this will be the name after ?id=

              include ('contact.php');

// page it corresponds to

break;

 

 

                    default:

 

                        include ('default.php');

 

                        break;

 

 

 

 

 

                }

 

 

 

                ?>

 

does that help ? Make it index.php and place all your contact in default.php

Link to comment
https://forums.phpfreaks.com/topic/118669-clean-urls/#findComment-610965
Share on other sites

<tr>

<td class="box" style="border-bottom: 1px solid rgb(52, 73, 102);" width="167">

 

<a href="contact.php">Contact</a></td>

</tr>

 

That is what I have so far, how can i change it where like contact is index.php?=1

The way you are trying to do it is bad for search engines, also it not very user friendly. In order for me to quickly go to your page I have to know the internal number reference. Whereas, tutorials are at tutorials.php. Catch my drift?
Link to comment
https://forums.phpfreaks.com/topic/118669-clean-urls/#findComment-610977
Share on other sites

If you're url is this:

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

 

Then in index.php use $_GET['page'] to retrieve the page number from the url.

 

Now to serve whatever page you'll need to assign each page a number, eg 1 = tutorials.php, 2 = sounds.php etc, like so

$pages = array(1 => 'search.php', 2 => 'sounds.php', 3 => 'otherpage.php' etc);

 

Now to serve the requested page you'd do:

if(isset($_GET['page']) && is_numeric($_GET['page']))
{
    $pid = $_GET['page']
    if(isset($pages[$pid]))
    {
        include $pages[$pid];
    }
    else
    {
        die('404 Note Found');
    }
}

Link to comment
https://forums.phpfreaks.com/topic/118669-clean-urls/#findComment-610991
Share on other sites

not really.

 

www.PhonePwners.com is my website (im working on it)

and want it where I can click any of the nav links

and have them like index?=1 - 5

instead of contact.php, call.php, sound.php, ect.

 

 

i dont really care about search eng. and stuff..

I am well aware of what you want. But its your grave.
Link to comment
https://forums.phpfreaks.com/topic/118669-clean-urls/#findComment-611012
Share on other sites

I do this with one of my pages (with success).  Just some things to consider:

 

1. if you use self recursive pages (pages that call themselves to process form data) use sessions to store the page index.  On your index.php page, include something like this:

 

<?php
session_start();
function pageTranslate($id){
switch($id){
	default: return 'default.php';
	case 'users': return 'users.php';
	case 'stats': return 'stats.php';
}
}




$site = isset($_GET['site']) ? pageTranslate($_GET['site']) : (isset($_SESSION['site']) ? $_SESSION['site'] : 'default.php');
$_SESSION['site'] = $site;

include('$site');
?>

 

This first checks the get variable 'site' to see if a different page is being requested.  If so, it translates the page reference into the proper php file name and stores it in the session variable.  If a different page isn't being requested, it just uses whatever is stored in the session variable.  If there is nothing, it show's the default page.

 

now you only need to specify 'site' in the url when switching to a new page.  You can call index.php all you want and it will continue to call the same page.  It REALLY makes life easier.

 

 

2.  Transform that pageTranslate function into one that queries a mysql database.  You can add and reassign pages by moving stuff around in a database instead of editing the source.  Use the same database table to generate your links.  This makes it easier to implement user access levels too, as you can limit what links are shown to certain users and validate the link against their access rights before loading the page.

 

3.  Learn to love modrewrite for apache and use it for common pages.  Say you access the forums.php page with $site = forums and tutorials.php with $site = tutorials.php.  Write modrewrite rules to that www.PhonePwners.com/forums is translated to www.PhonePwners.com?site=forums and www.PhonePwners.com/tutorials is translated to www.PhonePwners.com?site=tutorials.  You don't have to do it to all of your sites, but it is handy for direct access to certain parts.

 

Link to comment
https://forums.phpfreaks.com/topic/118669-clean-urls/#findComment-611074
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.