PHP


  • (PHP) Using route groups in Laravel to protect routes

    To protect routes, in Laravel, from unauthorized visits you can use route groups. All routes in group will be affected by the auth before filter. [php] Route::group(array(‘before’ => ‘auth’), function() { Route::get(‘controlpanel’, ‘CustomerPanel@showPanel’); Route::get(‘secret’, ‘Secret@showSecret’); Route::post(‘setup’, ‘SetupController@doSetup’); }); [/php]

    read more…

  • Simple picture/file upload script

    Simple picture/file upload script

    Here is a simple tutorial script that uploads a file to a folder on the server. In this example it is assumed that the file is an image and it will be outputted on screen in an img-tag. But the file uploading mechanics works for any file type.

    read more…

  • How to make OSX use MAMP php instead of system version

    Getting OSX to install Laravel properly is a minor nightmare. Here are some good instructions on how to get it to use MAMP php instead of the broken default one that comes with OSX. https://gist.github.com/irazasyed/5987693

    read more…

  • (PHP) Simple pagination

    Here’s a simple way to paginate when getting large amounts of posts from the database.

    read more…

  • (PHP) Simple gallery with thumbnail generation

    This is an enhanced version of this It’s a VERY simple php gallery. You could develop it in any direction. This one only supports jpg, but that could be augmented as well. Here’s what it does: Allows the user to choose an image and enter a title (or caption). Uploads the image to a folder…

    read more…

  • Simple function to see if a number is Even or Odd.

    Sometimes you need to check if a number is even or odd. A simple way to do this is using the modulus operator (the %-sign). It will calculate and return the remainder when dividing a value with another value. So how do you use that to find out if a number is even or odd?…

    read more…

  • (PHP) Simple e-mail contact form.

    A simple contact form, just for reference. Will add more info later on… [php] <?php if (isset($_POST[‘submit’])) { $name = $_POST[‘name’]; //name of sender $email = $_POST[’email’]; //e-mail of sender $email = stripslashes($email); $subject = $_POST[‘subject’]; //e-mail subject $subject = str_replace(array("\r\n","\r","\n"), "", $subject); //remove any linebreaks to keep from code injections $message = $_POST[‘message’]; //…

    read more…

  • Convert MySQL timestamp to PHP date

    If you save your date in the format of timestamp in your MySQL database, and want to output it like this: [php] $result = mysql_query("SELECT * FROM articles"); $row = mysql_fetch_array($result); $date = $row[‘timestamp’]; echo $date; [/php] Your date come out looking something like this: 2011-01-30 20:54:12 So it’s formated like YYYY-MM-DD HH:MM:SS But what…

    read more…

  • (PHP) How to make a simple gallery

    This is just a VERY basic gallery that you can modify to suit your needs. For example you could add columns in the database and store more info about the images (date, size, tags etc.). You could very easily make the output use Lightbox or similar images viewers. And you could of course do a…

    read more…