Skip to content

Instantly share code, notes, and snippets.

View devuri's full-sized avatar

uri devuri

  • Mexico
View GitHub Profile
@devuri
devuri / ContactForm.md
Created January 13, 2019 20:35 — forked from patotoma/ContactForm.md
secure php contact form

Secured PHP Contact Form

<?php
  if(isset($_POST['submit'])){
    $name = htmlspecialchars(stripslashes(trim($_POST['name'])));
    $subject = htmlspecialchars(stripslashes(trim($_POST['subject'])));
    $email = htmlspecialchars(stripslashes(trim($_POST['email'])));
    $message = htmlspecialchars(stripslashes(trim($_POST['message'])));
    if(!preg_match("/^[A-Za-z .'-]+$/", $name)){
@devuri
devuri / download-unzip.php
Created December 1, 2018 20:51 — forked from philipp-r/download-unzip.php
Download and unzip file with PHP
<?php
// get latest german WordPress file
$ch = curl_init();
$source = "https://de.wordpress.org/latest-de_DE.zip"; // THE FILE URL
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);
@devuri
devuri / .htaccess
Created November 12, 2018 17:12 — forked from voku/gist:d958041e7b1c19356e721de1eda1e6f8
.htaccess with many options + description
# Apache Server Configs v2.14 | MIT License
# https://github.com/h5bp/server-configs-apache
# (!) Using `.htaccess` files slows down Apache, therefore, if you have
# access to the main server configuration file (which is usually called
# `httpd.conf`), you should add this logic there.
#
# https://httpd.apache.org/docs/current/howto/htaccess.html.
# ----------------------------------------------------------------------
@devuri
devuri / .htaccess
Created November 12, 2018 17:04 — forked from styfle/.htaccess
Apache config for a https enabled, secure headers, cache headers, etc
## Set security headers per https://observatory.mozilla.org
Header set Strict-Transport-Security "max-age=15768000" env=HTTPS
Header set Content-Security-Policy "frame-ancestors 'self'"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options "nosniff"
## Add some rewrite rules per https://stackoverflow.com/a/13997498/266535
RewriteEngine On
#Header: X-Frame-Options for XSS Protection
add_header X-Frame-Options SAMEORIGIN;
#Header: X-Content-Type Options
add_header X-Content-Type-Options nosniff;
#Header: X-XSS Protection Header
add_header X-XSS-Protection "1; mode=block";
#Header: Strict-Transport-Security
add_header Strict-Transport-Security "max-age=15768000; includeSubdomains; preload";
#Header: Content-Security-Policy
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.api.twitter.com https://gist.github.com https://syndication.twitter.com https://platform.twitter.com https://js-agent.newrelic.com https://*.nr-data.net https://*.wp.com https://*.gravatar.com https://*.wp.com https://pagead2.googlesyndication.com https://ssl.google-analytics.com https://connect.facebook.net https://www.google-analytics.com https://cdnjs.cloudflare.com https://ajax.cloudflare.com; img-src 'self' data: https://pbs.twimg.com https://platform.twitter.com https://syndication.twitter.com https://dashb
@devuri
devuri / php-pdo-mysql-crud.md
Created October 22, 2018 02:58 — forked from odan/php-pdo-mysql-crud.md
Basic CRUD operations with PDO and MySQL

Basic CRUD operations with PDO

CRUD = Create, Read, Update, Delete

Open a database connection

$host = '127.0.0.1';
$dbname = 'test';
$username = 'root';
@devuri
devuri / create_countries_table.php
Created October 19, 2018 06:50 — forked from nissicreative/create_countries_table.php
Laravel Countries Table Migration
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCountriesTable extends Migration
{
/**
* Run the migrations.
@devuri
devuri / editor-add-roles.php
Created September 11, 2018 14:20 — forked from chrisguitarguy/editor-add-roles.php
Allow users with the role editor to add users to WordPress -- but only subscribers.
<?php
/*
Plugin Name: Editors Add Users
Description: Allow editors to add user roles
Author: Christopher Davis
Author URI: http://www.christopherguitar.me
License: GPL2
*/
register_activation_hook( __FILE__, 'wpse42003_activation' );
@devuri
devuri / give5stars.php
Created August 30, 2018 18:06 — forked from mathetos/give5stars.php
Shortcode to display number of 5-star ratings of a plugin on the WordPress.org Plugin Directory (aka Plugin Repo)
<?php
add_shortcode( 'give5stars', 'get_give_five_stars' );
function get_give_five_stars() {
$plugin_slug = 'give';
// Get any existing copy of our transient data
if ( false === ( $cachedresults = get_transient( 'wp-plugin-repo-data-' . $plugin_slug ) ) ) {
// It wasn't there, so regenerate the data and save the transient