Site Cloner PHP Script
Bargain Hunter PHP Script
Job Hunter PHP Script
Site Login and Access Control PHP Script

WordPress climbed to the top of free website builders a long time ago. As a developer who watched them battle it out from the beginning, I have used the platform on many occasions. It is a very fast way to build a website that can be managed very easily and has extra features called plugins that can add extra functionality with a click of the mouse.

However, the popularity and ease does not come without a price because it is a very popular target for hackers. Here is why. First of all, the second we build a WordPress website, its default coding will output public html that leaves a footprint saying “This site is built with WordPress”. Hackers built bots to crawl websites and if they are WordPress, or a specific modified WordPress site, it will attempt an automated attack such as registration which allows the user ‘in’ to alter code as a user.

As we look around the Internet, we can find many ways to avoid these issues, like deny user registration, use safe, updated plugins, updated WordPress version and strong passwords. In addition, if there is user registration, we must ensure it is only a subscriber because if we build a site and this gets switched to admin somehow, then,new registrations will be admins and they have ‘full power’ in the WordPress backend.

The problem? Is that this is a continual, tiring game. Our website could be up and running fine, unchecked for months. Meanwhile, the day an exploit is known and becomes public, the hacker could have done his damage because we did not act fast enough top fix the exploit.

For this reason, we must stay on top of WordPress installations if we use it. Otherwise, building a strong app with Laravel Framework or html/css/js can keep exploits more at bay.

After spending many part time hours ‘Googling’ for solutions to adding Vuejs to older and the latest Laravel 5.8 installation, I felt the necessity to publish this complete tutorial for adding Vuejs to Laravel in order to build SPA (Single Page Applications).

In modern times, Laravel 5.8 comes shipped with Vuejs. With older versions which may be downloaded, like admin templates from Codecanyon, we need to perform other operations to include it to an older app.

So, let’s separate the Laravel 5.8 from the older versions. Nevertheless, the same operations for older versions can be implemented to Laravel 5.8 too because it simply involves downloading Vuejs and Vuejs router, adding the files and using them.

Laravel 5.8

Since Laravel 5.8 comes shipped with Vuejs, we can add it and use it via the following commands which will install the node modules listed in the package.json file.

  • Step1: composer update
  • Step2: rm -rf node_modules
  • Step3: npm cache clean --force
  • Step4: npm install
  • Step5: npm outdated
  • Step6: npm install
  • Step7: npm run dev
  • Step 8 npm run watch

Once we have that, all we really need to do is make changes to the file resources/js/app.js

When we run the command ‘npm run watch’, we can take advantage of it being recompiled after we make changes to the file in order to view our results. With that said, the code below can be used to make it run as a single page application. Keep in mind, this example is used on the default template that comes shipped with Laravel.

Routes routes/web.php

The files routes/web.php needs the following line(s) to be able to use an SPA. We can use it for the base url or create a path with vuejs to run the SPA.

Route::get('/vuejs/{any}', 'SinglePageController@index')->where('any', '.*');
Route::get('/{any}', 'SinglePageController@index')->where('any', '.*');
After we add the route, we need to make the SinglePageController. We can make the controller with the following command.The controller will be located in the folder app/Http/Controllers. Alternatively, we could always create it manually by creating a file called SinglePageController.php. php artisan make:controller SinglePageController
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SinglePageController extends Controller
{
    //
    public function index() {
        return view('app');
    }
}
Now that we have our controller that returns the view file app.blade.php, we need to make that file and ensure it has the code below that will handle the SPA inside the div tag with the id equal to ‘app’. With the code block, the router-link handles the links while the is where the actual custom content will be located.
<div id="app">

<router-link to="/vuejs/foo">Page Foo</router-link>
<router-link to="/vuejs/bar">Page Bar</router-link>

<router-view></router-view>

</div>

The code below is a simple boilerplate for app.js

require('./bootstrap');

import Vue from 'vue'
import VueRouter from 'vue-router';
window.Vue = require('vue');

Vue.use(VueRouter);

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

const test = Vue.component('example-component', require('./components/ExampleComponent.vue').default);
const testbar = Vue.component('example-component2', require('./components/ExampleComponent2.vue').default);

const router = new VueRouter({
routes: [
{ path: '/vuejs/foo', component: test, name: 'Foo' },
{ path: '/vuejs/bar', component: testbar, name: 'Bar' },
{ path: 'vuejs/foo', component: test, name: 'Foo' },
{ path: 'vuejs/bar', component: testbar, name: 'Bar' },
{ path: 'foo', component: test, name: 'Foo' },
{ path: 'bar', component: testbar, name: 'Bar' }

],

mode: 'history'

});

const app = new Vue({
el: '#app',
router
});

With the above, we can name and keep our separate components for each page in the resources/js/components folder. That is it, we now have a basic SPA.

Older Laravel Versions

Like Laravel 5.8, we need to define routes in our file web.php. Two routes are shown below.
Route::get('/vuejs/{any}', 'SinglePageController@index')->where('any', '.*');
Route::get('/{any}', 'SinglePageController@index')->where('any', '.*');
Then, we need our controller for a single page app for which we can create using the basic command below.
php artisan make:controller SinglePageController
Once our controller is built, we simply load a view file called app.blade.php which will reside as resources/view/app.blade.php. The next block is code that loads that view.
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SinglePageController extends Controller
{
    //
    public function index() {
        return view('app');
    }
}
Next, we need the block below which handles the single page application links and content.
<div id="app">

    <router-link to="/vuejs/foo">Foo</router-link>
    <router-link to="/vuejs/bar">Bar</router-link>

    <router-view></router-view>

</div>

For the older Laravel installs, we can go to the vuejs website and download vue.min.js and vue-router.js.

Then, we can add place these scripts in the public/assets/js folder and add the reference to them in our blade files using:

‘<script type=text/javascript” src=”{{ asset(‘assets/js/vue.min.js’) }}”></script>’ and
‘<script type=text/javascript” src=”{{ asset(‘assets/js/vue-router.js’) }}”></script>’ .

Alternatively, we could use a path like:

‘<script type=text/javascript” src=”{{ ‘/js/vue.min.js’) }}”></script>’ too. These files can go below the footer scripts.

 <script>
     
        const Home = { template: '<div>home</div>' }
        const Foo = { template: '<div>foo</div>' }
        const Bar = { template: '<div>bar</div>' }

        const router = new VueRouter({
            routes: [
                { path: '/admin/vue', component: Home, name: 'Home' },
                { path: '/admin/vue/foo', component: Foo, name: 'Foo' },
                { path: '/admin/vue/bar', component: Bar, name: 'Bar' }
            ],
            mode: 'history'          
        });

        const app = new Vue({

            el: '#app',
            data: {message: 'Hello World'},
            router           
        });

    </script>

Conclusion

So there we are, we now have a couple of methods for adding Vuejs into our latest and older Laravel apps so we can build single page applications without a fuss.

After Googling and reading many sites about Laravel multi-tenant, multisite, or whatever you want to call it, I decided I wanted a simple DIY method to add subfolders which could have its own database.

I did not want to mess around with apache, .htaccess…rather just add and modify a few lines of code here and there. With that said, here are some details regarding how we can reach our end goal. This tutorial reached those results using Laravel 5.7

With this minor changes below, we can easily have subdirectories use a private database. Thus, each subfolder is completely unique for user, passwords and content.

We can take this farther and write a simple script to automatically make these changes with a click of the mouse for any new subfolder we wish to create.

1. Add a second .env file with new name
2. Add a second routes file and name it like web2.php. These routes will be like the original file except the routes will include the subdirectory
3. Make changes to bootstrap/app.php. This code checks for the subfolder 'test' and returns the appropriate .env file.  

Changes are shown below.

$app = new Illuminate\Foundation\Application(
    realpath(__DIR__.'/../')
);

$cur_dir = basename(dirname($_SERVER['REQUEST_URI']));


$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']
    === 'on' ? "https" : "http") . "://" .
    $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'];

// Display the complete URL

$urlParts = explode('/', str_ireplace(array('http://', 'https://'), '', $url));

switch(array_pop(explode($_SERVER['HTTP_HOST'], $urlParts[1]))){
    case 'test':
        $app->loadEnvironmentFrom('.env.sub1');
        break;
    default:
        $app->loadEnvironmentFrom('.env');
        break;
};
4. Make changes to app\Providers\RouteServiceProvider.php
Change the map method by adding the new method which will include the new routes file. This web route method call for $this->mapWebRoutes2(); must be above the original $this->mapWebRoutes();

Notice a the new method calling the web2.php route file too shown last.

public function map()
    {
        $this->mapApiRoutes();
        $this->mapWebRoutes2();
        $this->mapWebRoutes();
    } 

protected function mapWebRoutes2()
    {
        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(base_path('routes/web2.php'));
    }


Online Marketing in 2018

2018 is now upon us and the web is still steamrolling as the best place for online marketing. Since Internet marketing and can make or break a business, I have come up with a plan that can be used to avoid pitfalls and generate useful leads.

The 7 topics of Internet marketing discussion are SEO, SEM, content marketing, social media, ppc, Google Business Listings and Structured Data Markup. Since every website will receive traffic from various sources at different rates, I have put forward a list of the top places where you can make a presence and attract visitors and friends.

SEO

SEO in 2018SEO is the short hand term for search engine optimization. Most people online know the meaning of seo and tend to have a wanting to rank high organically with the search engines. With proper coding, text, images, links and document structure, this can be a pretty straightforward procedure from the start. But, it can be tricky and patience is required.

Although the ultimate outcome cannot be achieved overnight, you can acquire excellent results relatively quickly. It helps to have strong writing, coding and reporting skills in order to have an edge of the competition.

When pages are built to gain organic traction, you must remember to test for local terms to hit the desired audience. For example, a recent survey explained that 17% of people searching don’t use a local term. It also explains that 21% of youth do and a whopping 63% of older searchers do add a local term. Keep that in mind; especially if your market is an older audience, or maybe someone who prefers using a local modifier as the results without one are often irrelevant.

SEO just not mean just pleasing Google. For example, in Canada you can find estimates that ~21% of searchers use Yahoo and another 9% use Bing; which are both owned by Microsoft. Essentially, the combination can be attributed to almost 30% of web surfers. This may be slightly less than half of the queries that Google receives, but they do cater more to SEO techniques like content writing and proper coding than does Google.

Therefore, always make Yahoo and Bing a high priority because they will grade your documents an ‘A’ like a teacher while Google can make it very hard to show up and conquer the established competition. Even though that is just the way it is, your efforts will be rewarded from them too, although a different process.

SEM and PPC

sem 2018Search engine marketing and pay per click advertising can be implemented immediately in various forms. Typically, they are paid ads which are displayed when someone browses the web using specific keywords.

The ads can be used to display broad matches, phrase matches and exact matches. In addition, you can add negative keywords like free so that when people search for ‘tacos in Anaheim’ they will find you, but when they search for ‘free tacos in Anaheim’ they will not.

In rural areas, Adwords and Bing Ads are typically much more affordable and it is cost efficient to get to the top and stay there.

Asides from traditional search ads, joining paid directory websites and others listings can bring in referral traffic too.

Content Marketing

2018 content marketingIn general, I see online content marketing as a writer’s dream, and the most common source of marketing weakness in most websites. For whatever reason, whether it reminds someone of those dreaded University papers or a high school dropout that hated writing anything down, people just tend to want to avoid doing this and it looks as though they would rather save their writing bursts for social media where social wording is natural, short and sweet.

Since content marketing works well in all search engines; especially Yahoo and Bing which seems to make coding and content a priority, one should use this method to grab the bull by the horns and go to uncharted territory.

But, this method does not best as a marathon, rather than a short sprint. As a site is updated regularly, search engines will take notice. You will likely find that other pages and your site as a whole will show traffic increases that resemble a hot trading stock. Take away the momentum and it can drop the other direction.

Thus, creating content regularly is a key. In fact, once or twice a week is not overdoing it.

Social Media

social media marketing 2018Social media is a great place to build awareness. Again, there are some tricks to making social media be effective. Posts should be published often, and local ads and posts can be boosted from time to time as a mixture of organic and paid advertising will get the word out; especially if people follow your page.

Google Business Listing

Google Business listingFor any established business or new business, building a Google business listing should be automatic.

Structured Data Markup Helper

Adding Structured Data Markup to your websites can allow for alternative presentations when your site is crawled; such as displaying future events. There are various formats that can be used to display your results, but one stands out; JSON-LD. JSON-LD is a simple snippet of JSON that can be added inside script tags. The two links below can be used to create and test the markup.

https://www.google.com/webmasters/markup-helper/
https://search.google.com/structured-data/testing-tool

This post will explain how to link images, header and footer files across all folders. For example, let’s say you want to create a subfolder for seo purposes. In this case, let’s create a new folder called new-york. Meanwhile, our files in the root folder had all the css, images and javascript. Since the plan is to keep the same look, we only want to use the header and footer file from the root folder and allow those links to work perfectly.

However, if you do this and include the header to the subfolder with ‘include(“../header.php”);’, it will include that file. The issue is that the default path for the the files in the subdirectory will not link up because the path takes on the folder of the file in the new-york directory.

Luckily, there is one easy trick to allow everything to work flawlessly, thus, you only need one file in the new-york folder to utlize all css, images and js of the root folder. The simple line of code is the self closing base tag. An example is shown below with a line of code that can be added to the file in the new-york directory.

Do note that placement is critical. It should be positioned above all links to css and js; otherwise any links above it will use the path in the current directory. Both examples shown below will work.

<base href="example.com" />

 

<base href="/" />

202220192017201620152014201320122011201020092008

As a Linux enthusiast, particularly Ubuntu for home pcs, I had decided to write this article to explain why I have really taken to Ubuntu Mate. If I could sum it up in two words, it would be Ubuntu compatibility.

Several years ago, I had an old HP laptop that came with Windows Vista for which I wanted to install Ubuntu. After installing Ubuntu 12 and 14, the graphics did not not work properly out of the box. Even with some tinkering, there was issues. But, when I installed Linux Mint, it worked fine.

However, I had used Ubuntu extensively throughout the years and really liked the forums, always kept a copy of the book ‘Ubuntu Unleashed’ close to my workstation and was brand faithful. Thus, although I liked a lot about Linux Mint, especially the GUI, it always felt like I was substituting for my favorite Linux flavor.

Hence, if you have a Linux background, you may know what I am about to say next. When I first installed Ubuntu Mate 16 in the same old laptop, everything went perfect. In addition, I really liked the GUI and color scheme.

Since then, I bought several old laptops at auctions and have installed them without any issues as well.

Finally, my new Raspberry Pi3. I bought a new 16GB micro SD card and installed the Ubuntu Mate image designed for the Raspberry Pi. Again, I was very impressed how well it performed.

That’s it, my little story about Ubuntu Mate and why I have it in four of my pcs.

The idea here is to run a Linux cron job to reset a mySQL database at the desired interval. In the case of this tutorial, the interval is every two hours.

The code below clearly shows how this can be done in its entirety. It is a cron file for the user named myUser. Although it appears that it has 4 cron sections, note that to are commented out. Also, note that the top two lines of cron commands and bottom two are for 2 different databases.

The top two cron jobs have backticks with backslashes that are required for database names with hyphens, but the latter two lines use underscores where they are not required.

So, you may notice that the top line that is commented out is nice and easy. But, you may also find that it is only useful when you want to dump data into an empty database. Thus, the uncommented option, will run two mysql commands that drop and create a database for the desired user ‘myUser’, then dumps the data from a sql file into the database.

That is all there is to it.

SHELL=”/usr/local/cpanel/bin/jailshell”

#0 */2 * * * mysql -u myUser -pmyPassword myUser_my-DB < /home/myUser/cron/db.sql >/dev/null 2>&1

0 */2 * * * mysql -u myUser -pmyPassword -e “DROP DATABASE \`myUser_my-DB\`; CREATE DATABASE \`myUser_my-DB\`”;  mysql -u myUser -pmyPassword myUser_my-DB < /home/myUser/cron/db.sql >/dev/null 2>&1

#0 */2 * * * mysql -u myUser -pmyPassword myUser_my_db < /home/myUser/cron/db.sql >/dev/null 2>&1

0 */2 * * * mysql -u myUser -pmyPassword -e “DROP DATABASE myUser_my_db; CREATE DATABASE myUser_my_db”; mysql -u myUser -pmyPassword myUser_my_db < /home/myUser/cron/db.sql >/dev/null 2>&1

If you ever have used a theme or script, you will often see an element with various classes attached to that element; such as ‘<div class-=”red black”>’. As you may have already expected, the element makes reference to the red and black classes.

That is the easiest part while applying the style to the element is only a little more involved. If the single element contains 2 classes, how is the style interpreted from the stylesheet? To make this a little more clear, add the code below to the final stylesheet.

As you can see below, the element can access all 3 colors. But, the priority is top down for the single classes while the reference using .black.red takes precedence. Thus, the actual color of the text is blue even if you moved .black.red to the top. But, if you deleted .black.red and shuffled the order for .red and .black you will see that color will change to reflect the last single class.

<style>    
    .black{color:black}
    .red{color:red} 
    .black.red{color:blue}  
</style>

<div class="red black">My Text</div>

 

Now, try the code below. As you can see, the color is now red, because red overrides black and the use of !important will stick unless it is overridden by another !important.

<style>
    .black{color:black}
    .red{color:red !important}
    .black.red{color:blue}
</style>

<div class="red black">My Text</div>

 

Finally, try the code below. As you can see, the color is blue as you may have expected.

<style>
    .black{color:black}
    .red{color:red !important}
    .black.red{color: blue !important}
</style>

<div class="red black">My Text</div>

 

Now, for one little twist. Move the .black.red above .black so it looks the block below. As you can see, .black.red !important overrides anything below. Also, if you had the same order without !important, the text color would be blue too.

<style>
    .black.red{color: blue !important}
    .black{color:black}
    .red{color:red !important}    
</style>

<div class="red black">My Text</div>

GRUNT

Install Grunt and usage

1. Install the command-line interface

npm install -g grunt-cli

 

2. With the command line, navigate to the folder where you want to run grunt; such as a web application or website folder.

cd myfoldername

 

3. Install Grunt locally

npm install grunt –save-dev

 

4. Make a simple grunt file called gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
    jshint: {
      files: ['test.js'],
      options: {
        globals: {
          jQuery: true
        }
      }
    },
    watch: {
      files: ['<%= jshint.files %>'],
      tasks: ['jshint']
    }
  });

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');

  grunt.registerTask('default', ['jshint']);
  console.log('File Changed');

};

 

5. Make a simple package.json file or run the command ‘npm init’ to make it from the command line. Below is an example of a package.json file with all desired and required dependencies.

{
  "name": "Test-Project",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-concat": "~0.1.3",
    "grunt-contrib-jshint": "^1.0.0",
    "grunt-contrib-uglify": "^2.0.0",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-livereload": "^0.1.3"
  }
}

 

Here is how dependencies can be installed.

npm install grunt-contrib-jshint –save-dev
npm install grunt-contrib-watch –save-dev
npm install grunt-livereload –save-dev

 

GULP
Here is how to get up in running with Gulp.

Install globally just as you would Grunt.

npm install -g gulp

 

Go to desired folder.

cd myfoldername

 

Create a simple package.json file or run the command ‘rpm init’ to create it in the command line. See sample package.json file below.

{
  "name": "test",
  "version": "0.1.0",
  "devDependencies": {
  }
}

 

Install Gulp locally

npm install gulp –save-dev

 

Create a file called gulpfile.js and add your desired task(s). Sample gulpfile shown below.

var gulp = require('gulp');

livereload = require('gulp-livereload');

gulp.task('watch', function () {
    livereload.listen();
    
    gulp.watch('test/*.html').on('change', function(file) {
        livereload.changed(file.path);
        console.log('File Changed');
        gutil.log(gutil.colors.yellow('HTML file changed' + ' (' + file.path + ')'));
    });
});

 

Add required dependencies. Doing this will automatically modify package.json too.

npm install gulp-concat –save-dev
npm install –save-dev gulp-livereload
npm install gulp-uglify gulp-rename –save-dev

 

Here is how package.json will look after dependencies are installed.

{
  "name": "my-project",
  "version": "0.1.0",
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-concat": "^2.6.0",
    "gulp-livereload": "^3.8.1",
    "gulp-watch": "^4.3.9"
  }
}

 

Le’t run the watch task and see the console change when any html file in the test folder is modified.

gulp watch