Skip to content

Instantly share code, notes, and snippets.

@joseporiol
joseporiol / is_https.php
Created January 20, 2014 14:17
Check If Server is HTTPS
if ($_SERVER['HTTPS'] != "on") {
echo "This is not HTTPS";
}else{
echo "This is HTTPS";
}
@joseporiol
joseporiol / csv_from_phparray.php
Created January 20, 2014 14:18
Generate CSV from PHP Array
function generateCsv($data, $delimiter = ',', $enclosure = '"') {
$handle = fopen('php://temp', 'r+');
foreach ($data as $line) {
fputcsv($handle, $line, $delimiter, $enclosure);
}
rewind($handle);
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
@joseporiol
joseporiol / unzip.php
Created January 20, 2014 14:19
Unzip file
function unzip_file($file, $destination) {
// create object
$zip = new ZipArchive() ;
// open archive
if ($zip->open($file) !== TRUE) {
die ('Could not open archive');
}
// extract contents to destination directory
$zip->extractTo($destination);
// close archive
@joseporiol
joseporiol / sanitize.php
Created January 20, 2014 14:20
Sanitize Database Inputs
function sanitize_input_data($input_data) {
$input_data = trim(htmlentities(strip_tags($input_data,“,”)));
if (get_magic_quotes_gpc())
$input_data = stripslashes($input_data);
$input_data = mysql_real_escape_string($input_data);
return $input_data;
}
@joseporiol
joseporiol / find_links.php
Created January 20, 2014 14:22
Find all links on a Single Page
@joseporiol
joseporiol / download_and_upload.php
Created January 20, 2014 14:23
Just Download & save a remote image on your server using PHP
$image = file_get_contents('http://www.url.com/image.jpg');
file_put_contents('/images/image.jpg', $image); //save the image on your server
@joseporiol
joseporiol / delete_dir.php
Created January 20, 2014 14:25
Delete directory recursively
<?php
/**
* Delete a file, or a folder and its contents (recursive algorithm)
*
* @author Aidan Lister <aidan@php.net>
* @version 1.0.3
* @link http://aidanlister.com/repos/v/function.rmdirr.php
* @param string $dirname Directory to delete
* @return bool Returns TRUE on success, FALSE on failure
*/
@joseporiol
joseporiol / url_exists.php
Created January 20, 2014 14:26
Test if an url exists or not
function url_exists($url) {
$hdrs = @get_headers($url);
return is_array($hdrs) ? preg_match('/^HTTP\/\d+\.\d+\s+2\d\d\s+.*$/',$hdrs[0]) : false;
}
@joseporiol
joseporiol / show_ddl.sql
Created January 21, 2014 10:16
Showing DDL
SELECT DBMS_METADATA.get_ddl ('TABLE', 'TABLE_NAME', 'USER_NAME') FROM DUAL;
@joseporiol
joseporiol / current_schema.sql
Created January 21, 2014 10:17
Get current schema
SELECT SYS_CONTEXT ('userenv', 'current_schema') FROM DUAL;