Jump to content

php navigation - the professional way!


barbs75

Recommended Posts

Hi guys,

 

just a quick question regarding navigation on php sites.....

 

Ok, my websites dynamic pages are using php, im just wandering how to navigate between php pages on a php website??

 

For example, i look at a lot of php websites, and they have in the URL "http://www.phpfreaks.com/forums/index.php?action=post;board=1.0", basically they all have the action or whatever in the URL, so is php naigation donw within the URL??

 

I dont really understand!!

 

I have my homepage at the moment as index.html, but then have a login page which is login_form.html, which when a form is submitted then calls login_process.php, so the url will be "www.go4home.co.uk/login_process.php" shouldn't this rather be something like "www.go4home.co.uk/action=register;id=9876443" something like that???

 

The only reason i ask is that i came across passing variables over the URL for creating an activation email, where you have on the activation link, a scrambled (md5) username, which so when the user hits the link, it changes the activate status of the username variable in the database to show they have activated their account.

 

So are SESSIONS therefore used for php navigation, hence "www.go4home.co.uk/action=register;id=9876443"

 

Where a page might have a session name as 'register' etc

 

If someone could give me some insight on this, because it has been bugging me for quite sometime, looking at loads of other websites, you always wander how you should be doing things, to ensure your website is professional and secure

 

my URL to my website is www.go4home.co.uk if you want to have a look at my site

 

cheers

 

Craig

Link to comment
Share on other sites

Ok...let's see if I can shed some light on this. Sites with a CMS system (forums included) have pages that are all generated dynamically. So, index.php is kind of like switching station, where it will output different content based on the data passed to it.

 

But, with what it looks like, you don't need to worry about funneling everything through index.php. login_form.html should pass data to login_process.php via a form with a method of POST. Then, login_process.php can access that information with $_POST.

 

The action=someaction;id=12345 is not some PHP standard, it's just a format of passing data in the URL that the site picked. If you need more help on how to use forms to submit data, check out http://devzone.zend.com/node/view/id/626

 

Hope that helps.

Link to comment
Share on other sites

PHP navigation can occur through the URL, but it doesn't have to.

 

There is nothing more or less professional about a site with URLs like:

index.php
contact.php
about.php
login.php

vs.

index.php
index.php?page=contact
index.php?page=about
index.php?page=login

 

They both accomplish the same thing and they both require the same amount of URLs to navigate around.  After all if your site has 9 distinct pages it has to have 9 distinct URLs, no matter which method you choose.

 

The difference is that the second example has only a single php script, i.e. index.php, that acts as the entry point for every page.  This makes it easier to perform application setup, such as database connections.  It has the trade off that index.php is now a more complicated file.

 

If you try to shove the logic for every single page in your site into a single PHP script, you will quickly overwhelm yourself.  The file will become quite large and difficult to maintain.  You'll start asking how you can maintain such a mess and the answer is by better code organization, via functions and / or objects.

 

Look at it this way, by using URL parameters you decrease the number of actual script files that reside on your server, but you still have to write all the code and logic.  There's a certain threshold of site size where the first method is better, namely small personal sites.  As your site starts to grow in size and complexity of functionality, the second method works better since when organized correctly, you can reuse a lot of code.  Basically the site is more maintainable over a long period of time.

 

The second approach also has the benefit of working well with mod_rewrite, which helps in creating search engine-friendly URLs.

 

About security, neither approach is inherently more secure than the other.  Security is something you have to build into your site, so no matter which approach you take if you don't add security features your site is insecure.

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.