I've been wanting to learn how to build a basic WordPress site and use PHP to interact with a MYSQL db. Pretty basic stuff and I'm an Oracle Dev so this is just me being curious. I also want the DB interaction to be hidden from the outside world so you have to login to view and run any of it. I've done a few order management type things in the past so that's what I'm basing this on. Add/edit/delete customers and orders. Just really simple stuff to start with.
So far I've done the following:
1. Built a basic Wordpress site, with a couple of normal pages open to everyone and then some password protected pages for the order stuff (more on this later). The order pages have simple forms on them with actions to either insert/edit/delete data from the DB. I've been using a plugin called Shortcode Exec PHP to handle the PHP in the pages as I couldn't get it to work when I created a template.php page from the existing post.php page as described on several WP sites.
When id's need to be passed between pages I've been using $_GET and $_POST as appropriate on the receiving page. I've done various things to ensure the variables are valid including isset, isnumeric, mqsql_real_escape_string and htmlspecialchars, etc.
2. The PHP to handle the actual inserts/updates/deletes I put into physical .php files which I sat in the root directory on the webserver. I just seemed easier to do it that way at the time.
3. Just played around with presentation using CSS and it all looked ok and seemed to work ok.
I knew the password protected pages weren't enough and I noticed they were being returned in Google search results. So I set the pages to private, added noindex/nofollow in WP and requested their removal from Google, which happened pretty fast. I then created a new user, created a new role with access to only private pages and redirected their WP login to the first private page.
I also noticed I could run the php files if I knew the URL and just added any old number for the id. So this is where I'm currently at. What's the best way to ensure these can't be run by anyone who isn't logged into the site ? I've read various options about changing directories and using .htaccess to limit access but I haven't been able to get my head around how that works, especially if I wanted to access this remotely. I was just looking at blocking everything but setting a whitelist for me locally but that didn't seem to make sense.
Or should I just continue with using the plugin and remove them from being physical pages and have them as shortcodes ? Would that stop them from being run from the browser ?
I'd appreciate any pointers.