eCommerce Site, php / html file - php

I'm in the process of building an eCommerce site for a college assignment. The question is, should all files be set up as .php? i.e. in what instance should or shouldn't be html? (Please note I've got the login and registration forms set up as .php which are currently connecting to a db). Many thanks.

I personally recommend you use .php files only for your website. In general .html files are used for templating and they only set up the 'view' of the page. By default, .html web pages can not use PHP code unless you set up the server to do so (For example using a .htaccess file as explained here)
It's really just as Bonner said, asking how long is a piece of string. The answer can differ depending on what you are doing. Based on what you are working on I still recommend you use .php as the file extension for your project.

Related

Is there a possible solution on how to hide file name in PHP or .htaccess?

I want to change my url path to this:
localhost/sampleproject/validation.php
to
localhost/sampleproject/
I want to secure my file path. is there a code in .htaccess? if there is I will create .htaccess but i have no clue where to start, still learning to php thank you
that type of change usually hides index.php if you need to run code in a validation.php i might suggest including it within your index.php you can do so conditionally if necessary using include() or require_once() if you do that the user will have no knowledge of that file on the fronted. here's some examples of that https://www.w3schools.com/PHP/php_includes.asp
reference the links in comments of your question but as I said generally with apache you can configure it to not show the index.php but other than that it's per folder basis.
you may also want to look into creating some routes to trick the browser abit if that's your approach.
here's an example http://blogs.shephertz.com/2014/05/21/how-to-implement-url-routing-in-php/
or you can always use a framework such as symfony or Laravel which have route implementations for you to use.
Happy Coding.

Running PHP scripts with Bolt CMS

So, this might be a stupid question. Bear with me, I'm new to CMS usage :P
Anyways, I'm using Bolt CMS to create a very simple website. For it, I just need a simple contact form, which means my server needs to be able to send out an email. I want to use PHP for this.
Now, how exactly should I handle this with Bolt CMS? The default configuration does not allow .php files to be uploaded, however I could easily change this in the main configuration, to allow for its type. My first guess was to try and upload it to either the theme folder, or the file folder for the theme. However, when I try to upload .php files they don't even show up in the folders I upload them to, even though it says the file was uploaded successfully. However, I'm unsure this would even be the best way to handle PHP scripts with Bolt CMS.
Anyone got any inputs to this? :)
Thank you!
For security reasons, Bolt will not allow you to run PHP scripts from inside Bolt. If this is something you need to have, there are two options:
Make it standalone. Create a contact.php on the server that handles it, and link to that.
The better solution would be to use an extension for that. Simpleforms (easy to implement, with a fair share of options), BoltForms (more options and allows for more control over the fields as well as uploads) or Simple Contact Form (very bare bones, but might be what you need).

Joomla 2.5 views - php vs html suffix

I'm looking at a site under development (at my wife's work). It's being built with Joomla 2.5.x, and it's using a Kunena template for the forum.
Each page on the site uses a single URL with PHP variables, e.g. www.sitename.com/index?option=com_content&view=article&id=96&Itemid=101.
However, on the demo site, the suffix is always .html even though the content is CMS/database-generated.
What I want to know is:
Why does the site at my wife's work use .php?...?
Where in the backend administration portal (to which I have access) are the settings for each view (presumably using a MVC framework)? Or are they only available by editing the PHP files directly?
Thanks.
Addendum
I found this documentation which helps explain #1. Still would like an answer to #2.
First, you should never edit a Joomla file directly. If there is ever somethign you can't do via a setting, override the file. Any changes you make in core files, besides potentially breaking things, will get overwritten on an update.
In terms of settings in general every view has an options button and you set default settings for the component there. There are then in general individual settings in items and menu items that override the defaults.
Kunena has more complex configuration and thus has its own complete UI.
Joomla has a setting for using either the raw url (which your site is using) or "Search engine friendly" (SEF) urls. The demo site not only uses SEF urls but also adds an html suffix to the end. The html really means nothing to the system and is just there. You could turn that off and the system would operate the same just without '.html'. (Locations would look like folders instead of files, I guess.)
If you access your administration system (www.sitename.com/administrator, most likely), you can go to Site->Global Configuration. Make sure you are on the "Site" tab and you should see SEO settings on the right side. These settings will change the urls between the demo's version and your own.
To use the mod_rewrite bit, you may have to convert an htaccess.txt file to .htaccess on the server: http://docs.joomla.org/How_do_you_convert_an_htaccess.txt_file_into_a_.htaccess_file%3F
To add a bit more, the demo site's url is ultimately converted back into the url that you see on your wife's work's site. The system operates based on option, view, id, and Itemid variables. The SEO settings convert this into search engine friendly phrases which I think help both search engines and people!

How to make use mod_rewrite to create pretty permalinks for a custom-built CMS PHP script meant for external distribution?

I am trying to build a CMS that will be used by other people, which means that I can't rely on editing the .htaccess files for mdo_rewrite. I have looked up methods for mod rewriting urls from http://example.com/index.php?category=food to http://example.com/category/food but most of them seem to rely on apache and editing the .htaccess file, which would only work if you are creating a script which, like public scripts like Wordpress, rely on being installed on an external user's server. How do I mod_rewrite from within the script so that the script either automatically edits the user's mod_rewrite settings in .htaccess (as in altering the rewrite rule in the file from within the script itself) or some other method that would work fo a CMS script that is solely written in PHP and intended to be used on another server.
If the script you are using, is making use of a popular framework, chances are they have installed a so called "routing" system inside the framework. That by itself allows nice URLs.
In fact, if you're using any commercial script for a webshop or something alike, they probably have a mod, plugin or component that allows nice URLs. Look it up or add additional info please. :-).

Need php template help and clean url help

I'm new to PHP and web development in general, but have been a programmer for 5 years. I'm trying to work on my own website from scratch using Notepad to edit my PHP files and WAMP for my server. I'm able to view my files fine in Safari, Chrome and Firefox, but not IE (which we all know IE isn't the greatest) because I'm using some HTML5 stuff. Anyways, I have an Includes folder that holds my files for my header, menu and footer. I have an index.php file that includes these files and displays them fine. In the center of the page is where I want the content. To try and keep clean urls, I made quite a few folders and put this same index.php file in there (e.g. Profile/index.php, Forums/index.php, etc.). I did this so when I went to localhost/mysite/profile/ it showed me the template I wanted to use. However, there has got to be a better way to use the template and a better way to have clean urls. I'm not currently hosting this site anywhere so I don't know if I'll have access to the htaccess file (not even sure what it is honestly, just seen it mentioned), but I was curious of having the folder structure (one folder for each menu item) is a normal or ok practice? I was also curious if there is a way to use the index.php without having to copy and paste it every time I make a small change. Any help would be appreciated. Thanks.
If you are planning on templating I suggest using an existing platform like Symfony, Zend Framework, or Smarty. Smarty is probably the easiest to get going with and it is (almost) purely for templating. Whereas Symfony and Zend Framework are big packages with lots of bells and whistles.
If I was going to be doing pure templating I would look at Smarty. I use Zend Framework for just about all my current PHP projects now but it has a pretty steep learning curve. Your first couple weeks will be frustrating.
As far as URLs go, .htaccess is probably the preferred method (at least in my book). Zend Framework and Symfony both have kind of default URL writing style that looks like http://host/controller/action where controller would be Profile or Forums. You wouldn't necessarily have to see host/profile/index, it could be host/profile or host/profile/edit, where edit is the action being performed.
Copying the index.php file is not really the way I would go. It seems messy and there are a few other options. If you want the urls to be clean and search engine friendly you should really have a look at url rewriting using .htaccess
You're saying that you're not sure if you will have a server with "access to the htaccess file" but if you can upload files you can always upload a .htaccess file as well -- the problem is that the web server is not always using them or might not have mod_rewrite enabled. In this case you can get your urls on the format of http://www.example.com/index.php?u=/Profile/foo (this is also my preferred way to handle url rewrites).
In your index.php just make sure to read the requested url parameter passed by mod_rewrite and include whatever files in the folder that you need. Actually, you don't even need a "physical" folder structure, you might want to implement it using classes or something like that. (I'm sure I would).
I would really recommend that you go have a look at a good PHP framework, CodeIgniter for example. Even if you decide to code everything from scratch, you would still learn a lot about best practices for url handling, databases, the MVC pattern, template engines, database abstraction layers and PHP coding in general.
your answer is the htaccess file, is converts the 'folder structure' to $_GET value's
for example,
if you're in website.com/Profile/ you can write an htaccess line that will convert that into website.com/index.php?folder=Profile
htaccess:
RewriteEngine on
RewriteRule ^/(.*)/$ index.php?folder=$1 [NC,L,QSA]
RewriteRule ^/(.*).html$ index.php?folder=$1 [NC,L,QSA]

Categories