Best way to hide back-end in PHP? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Im working on a PHP based web app which allows users to login. What would be the appropriate method of 404'ing all the back-end - (the actual application pages).
I've got a user-tools class which has a check-login function in it, that I use at the moment. If the user isn't logged-in, it redirects to a 404.
However I'm wondering is there a better way to set this up? Could I have a global page that has a list of all the pages that should 404 if the user isn't logged in? If so, how would you set that up?

Many website have all their traffic through a single entry point. In such a setup, you can define a constant in that single file, and check it in every file that is included, so you know whether the file was in fact loaded by the entry file. This method is implemented in MediaWiki for example.
Another solution is to put all the include files outside of the document root. Many frameworks (like CodeIgnitor and others) allow you to specify this directory, and allow you to put it anywhere you want. If it's outside the doc root, visitors cannot load files from that directory directly.

Related

how to create cms using php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
i'm a beginner in php but want to expand my knowledge. so i want to create a cms from scratch.
i already have an idea how to create a post. by inserting data to database
and populate the html file with the data(post) that came from the database
example this is my website
domainname.com/index.php --- and this is the address of my homepage
on my homepage, i want to show some preview of my each post.
something like this,
and if the user of the website click the post.
it will go to another page
domainname.com/postname.php
and with the data like this
so my question is how do the CMS create the file for every post.
the idea in my mind is creating the html file dynamically using php and naming the file with the name of the post. but is it a good practice? or am i doing it right?
While generating static files (whenever the admin interface is used to make a change) will work, it isn't a typical approach for a CMS.
Usually they will apply the front controller pattern (in which each request for a content page, despite having different URLs, is funneled through the same PHP program, something that is often achived with the Apache mod_rewrite module) and generate the requested page on demand.

Upload and Retrieve a file with PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've created a small website with PHP and MySQL. The website allows a user to fill in a questionnaire (which is saved in a database) and then an admin person needs to view and then upload results in PDF format so the original person can view them. In fact the admin person can upload multiple PDF's (over time not in one sitting) to give more feed back which need to be accessible to the user.
My question is, what would be the best way to do this? First, should I upload files via PHP or would jQuery or the like be better? Should each person get their own directory? (does it matter if there are 100's of users?) How can I read all the files that pertain to a particular person and then allow them to view/download it?
Thanks in advance!
you can use form and php to upload file. If you need validation do it with php (for server side validation) or javascript (for client side validation), i recommend that you do both.
To distingusih between user data, you can use prefix for filename with username or something (ie. user1_file1, user1_file2, user19_file18), since i think it will be messy to create folder for each user.
To give link for user to download just add "location" column to your user database that contain the file path in your server. With this, you can check their username and every file that they upload in your database.

Maintenance Page Control [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have hmvc-codeigniter I would like to know what the best way is to show one of my views/controller pages for maintenance mode. Where I can view website but any one else that is not on my ip bets directed to this certain view/controller.
I have tried many htaccess codes but non seem to work the way I am after. They still block me from viewing my own website when working on in maintenance mode.
is there a proper function that can add in to index.php in codeingiter that can do what I am after.
CodeIgniter features the Front Controller paradigm, so everything passes through index.php. I don't know how you set your website in "maintenance mode", whether it's through a relational database or if it's just through code.
The idea above ensures that if we add code to index.php, then we know for sure that it's the entry point to our application. A quick fix would be to add the following to index.php:
if($_SERVER['REMOTE_ADDR'] != 'xxx.xxx.xxx.xxx') {
die('Application is currently in maintenance mode. Please return shortly.');
}
While the fix above does resolve the issue, it's never a good idea to remove content unless you have an emergency situation (hacks, DB failure, etc.). You may want to setup a different staging server, work any updates on that server, and the apply them to production.

What should be the best place to store user preferences in PHP: database or files? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am developing a website using PHP and I'd like to know if it is better to store user preferences (such as language, background image, and so on) in a database or in a text file outside the public_html folder (to prevent public access to the info).
I ask this because I am worried about the time PHP takes to read a file and to send a query to the database, also it may slow down the database due the volume of queries sent by multiple users.
Usually I would store the user defined options in the database.
Some hints:
I load them only once in a request
sometimes I store all settings for a user in a blob if I have to use a relational database. This is dirty, but I can easily add new attributes
In high-traffic websites I would cache the retrieved object, using my MVC framework's cache mechanism
If caching to the file system becomes a problem, you can use databases like Redis, MemCached
Usually we don't put files in the DB but read this and compare with your situation : https://stackoverflow.com/a/22804/1529139 and https://stackoverflow.com/a/3751/1529139
Sorry for language problem ..
It is fully depends on your behavior of site. In which type of your project made. If you are using a MVC structure then create any directory at place of your bootstrap php page. Mean a main page. And store your source at that place.
Then make setting menu (Page ) for particular that will help to dynamically change the source identity and location path.
Storing in DB should be prefered, expecialy if later you have to load Balance between servers.

A simple one. Is this a folder, or a php/py file, with a hidden extension [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
So what does 9gag have for each of it's posts? A gag folder with thousands of single-file folders, or is it just a php (or py... I didn't check) file with a hidden extension?
Here is the link:
http://9gag.com/gag/a7LQzWw
BTW, I didn't choose the post by it's hilariousness :) Just a random post :)
Oh, and if it's a single file, isn't it memory consuming to have separate files for every post? Thank you for any replies :)
This is all assumption based off the URL and other sites that host large amounts of content in a similar fashion.
It's most likely an MVC (model, view, controller) web application, I can't tell what language. They'll be using some form of dispatching/routing (Apache's mod_rewrite for example) to get all requests through some common code.
9gag.com is the server. /gag/ is the 'controller', this controller has been coded to then know that the next part of the URL is the post/image ID. So it grabs the ID from the URL (or dispatcher already did this and passed the ID to the controller) and uses it to look up the content from a database (the model) and inserts it into a generic template (view).

Categories