0

I'm building website in php. For me is important to have pages with similar title and url. Like this: Title -> some content URL -> some-content.php

Each page has the content (articles) retrieved from mysql. Title also is retrieved from mysql.

So my question is: should I generate a .php file for each artivle or it is possible to have one php file with changing content and URL? How whould you do it?

Thanks for the attention

5 Answers 5

3

Definitly you shouldn't define new files for each article. You should have article controller in this controller you need retrieve articles from your model. In Articles you can have slug or id and pass this slug/id to template.

You could also check mod_rewrite to have nice and seo friendly urls.

Some pages to read:

Sign up to request clarification or add additional context in comments.

Comments

1

The "piles of PHP files" design pattern fell out of style over a decade ago. DO NOT DO THIS.

Modern PHP development encourages the use of a development framework like Laravel that gives you a solid foundation for building your application.

Most of these have a robust routing system that takes care of presenting clean URLs to your visitors while allowing significant flexibility in how those URLs are handled internally. This is a huge advantage to someone concerned about how their site is organized.

Comments

0

No need to make a PHP by page. In your html <head> you can change the title dynamically :

<head>
    <title><?php echo $titleFromDB; ?></title>
</head>

Don't forget to escape/protect the variable if the title can be edit by users.

4 Comments

Hi. thanks for attention. I already have the title changin dynamically.. The problem is with URL.. Is possible to change the url dynamically?
of course it is check my post use mod_rewrite with slugs and pass it as params. for example example.com/page.php?slug=best_page_ever could be coverted to example.com/best_page_ever
Sorry, my mistake. I misunderstanding your need. You can look at mod_rewrite and .htaccess file like @Robert says.
Thanks for the attention, now I have the idea what should I do
0

I suggest you use a framework like codeigniter which can handle the required structure of your files (MVC approach) and also helps you create SEO friendly URLs.

Comments

-1

I would definitely use one page with a changing url, title & content. It means 1 place to go when any issues occur.

Just make 1 page and use GET variables in the url to change what content is loaded.

e.g. test-page.php?content=content-id

this link is created using the id of the content from the sql table, you then get this id when the page is opened and use it to get the rest of the details from the database that will be used for your title and content.

I hope this makes sense

2 Comments

I absolutely detest URLs like this. For one, it has .php in the URL, something utterly irrelevant, and secondly it has this train-wreck of junk on the end that is simply asking to be tampered with by the user.
I completely agree, I was just trying to explain the logic in as simple a way as possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.