Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7693509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:06:20+00:00 2026-05-31T21:06:20+00:00

In PHP I am trying to write an article section. A totally fictitious article

  • 0

In PHP I am trying to write an article section. A totally fictitious article URL would be in the format:

http://www.example.com/articles/fix/appliances/how-to-repair-a-microwave/

What I am getting hung up on is how to make it so that I can make each part of the url properly show the data that is required and if they add anything thats not in the right format, it state page does not exist.

For example, if a visitor went to http://www.example.com/articles/ it would show a listing of all the articles. If they went to http://www.example.com/articles/fix/ it would show only articles under the fix category. If they went to http://www.example.com/articles/fix/appliances/ it would show only the articles under the fix appliances category, etc.

I can explode the $_SERVER[‘REQUEST_URI’] to evaluate which function in the PHP code I should perform. For example show a feed or show a category.

$match = explode('/', $_SERVER['REQUEST_URI']);

switch($match[2]) {
  case 'feed':
          show_rss();
          break;
  default:
          show_category();
          break;
}

My confusion, though, is how to differentiate between a category and an actual article. In the show_category() function, I could take the last part of the url path and check a database to see if an article exists using that path. If it does, show the article, else assume its a category. I am not sure, though, that this is the most efficient way of doing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:06:22+00:00Added an answer on May 31, 2026 at 9:06 pm

    I’m going to assume that you’re appropriately accessing your script in such a way that the script is running from a single generic location, but the best way to access the data you want is from $_SERVER['REQUEST_URI']. Personally I’d use mod_rewrite, but that’s a separate matter from your question.

    Since you’re providing the links to these pages, you could append an extension on your article key: http://www.example.com/articles/fix/appliances/how-to-repair-a-microwave.article/

    If a dash will always be present in the article key but never in a category key, you could preg_match for a dash.

    Otherwise, you’re pretty much set to check each key against the database. What I’d do instead, though, is run each entry against the category database. Presumably if it’s an article key, it won’t match against the category table, and then you can try to match it against the article table. That will be more efficient than trying to match every time against the article table.

    Edit: it’s actually more appropriate to say, it’s more efficient to check against the table that will be used most often. If people will be hitting the category navigation pages more often, then you should attempt to match the last key first against the categories table. If people will be hitting the article pages more often, then you should check against the article page first. This is just a matter of watching your server logs and reacting appropriately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write RewriteRule to redirect www.myweb.com/download/blabla.zip to > www.myweb.com/download/download.php?filedownload=blabla.zip this is
I'm following a tutorial on Zend Framework here (http://www.ibm.com/developerworks/opensource/tutorials/os-php-zend2/section2.html). I barely got started, but
I am trying to write a small PHP function that would go through a
I am new to php and trying to write a login function. Bit stuck
I am trying to write a php function to stop MySQL injection attempts. What
I am trying to write a PHP script that can upload multiple files. for($i=0;$i<count($_FILES['uploadimg']['name']);$i++){
I am trying to write a PHP script that uses the pdftk app to
I am trying to write a PHP script that listens for incoming $_REQUEST or
I'm trying to write a simple PHP MVC framework to play with. Right now,
I'm trying to write a php function that gets all the basic food data.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.