PHP / Forms

Introduction

Smarty package comes with PHP "micro framework" helping you to get started.
Is written from scratch but kept as simple as possible so you can extract what you need.

If you already use a php framework like Laravel, etc, you definitely don't need it. But there are also some helpers you might need.

An useful class might be php/sow_core/sow.smtp.php - a SMTP class using redundcancy to send emails. You can add to config.inc.php multiple SMTP email providers (your own hosting, Amazon SES, Mailgun, etc) and the SMTP class will try to send the email using the first available provider. If the first one fail, will try the next one and so on.

SOW PHP : functions.

All functions below are added to php/index.php (all of them are commented by default). You can uncomment one at a time to test/see how it's working on your local webserver. PHP 7.x is recommended but also works with 5.3+

/*

	+++++++++++++++++++++++++++++++++++++++++++
	Content of index.php
	All functions are commented by default!
	Here are uncommented for a clear view.
	+++++++++++++++++++++++++++++++++++++++++++

*/
require_once('config.inc.php');
require_once('sow_core/sow.init.php');
require_once('sow_core/sow.core.php');

/* Init */
$SOW = new SOW_Core;


/*

	Variables from $_POST and $_GET
	XSS Cleaner is used as a security plus. No other sanitization!
	Array $_POST is returned as it is!

*/
 echo $SOW->_postVar('email');			// return $_GET['email'] ; return null if not set
 echo $SOW->_getVar('email');			// return $_POST['email'] ; return null if not set
 echo $SOW->_requestVar('email');		// return $_GET['email'] -or- $_POST['email'] - autodetect - not $_REQUEST ; return null if not set




/*
	HTML TO PDF!

	Second param:
		'open' 		- open in browser
		'download' 	- download as a file
*/
 $SOW->html2pdf('This is my PDF! <br> Like it?', 	'open', 		null, 11, 'Helvetica');
 $SOW->html2pdf('This is my PDF! <br> Like it?', 	'download', 	"output_name.pdf", 11, 'Helvetica');




/*
	More functions
*/
 echo $SOW->ckmail('some@email.com'); 							// check for a valid email format & valid domain. return: null (invalid) -or- trim(strtolower($email_address))
 echo $SOW->user_device(); 								// return: mobile|tablet|pc 
 echo $SOW->user_ip(); 									// return: user IP
 echo $SOW->age_by_date('1982/06/29'); 							// Return age by date

/* Redirects - see the class for all codes! */
 echo $SOW->headerStatusSet(404); 							// Set header to: 404 not found
 echo $SOW->headerStatusSet(301, 'new-url-redirect.html'); 				// 301 redirect

 echo $SOW->full_url(); 								// full current URL
 echo $SOW->fix_url('www.google.com'); 							// add https: to url if mising
 echo $SOW->close_tags('<div>lorem <a href="#">ipsum'); 				// fix html unclosed tags
 echo $SOW->permalink('Smarty is a Multipuse Template! !!'); 				// create a permalink from a string (usable as URL)
 echo $SOW->remove_accent('ÎĂÎÂȘȚ ăîâșț litere în limba română ;)'); 			// remove accents (function used by permalink())

 echo $SOW->random_gen(10); 								// Random chars (leters & numbers)
 echo $SOW->random_gen(8, 'L'); 							// Random letters only
 echo $SOW->random_gen(6, 'N'); 							// Random numbers only

/* Curl */
 echo $SOW->curl_get($url, false); 							// CURL used to get content. Second param: false = disable SSL certificate
 echo $SOW->curl_post($url, $array, false); 						// CURL used to post content. Last param: false = disable SSL certificate
 echo $SOW->curl_api($url, $data, $method, $ssl); 					// $method = GET|POST|PUT|DELETE ; $ssl = false -OR- path to ssl certificate

/* Cookies */
 echo $SOW->cookie_set('cookie_name', 'cookie_value', expire_days, serialize); 	 	// serialize = true|false. default: false
 echo $SOW->cookie_get('cookie_name', unserialize[true|false]); 			// serialize = true|false. default: false
 echo $SOW->cookie_del('cookie_name');

 echo $SOW->xss_cleaner('string to clean'); 						// check & remove XSS by different patterns
 echo $SOW->words_limit('long string here', 100); 					// words limiter
 echo $SOW->byte2size(7897382942); 							// bytes to size (890Kb, 5Mb, 2.1Gb, etc).
 echo $SOW->file_download('path/to/file.pdf', 'download_as_name_optional.pdf'); 	// download a file from server instead of opening
 $SOW->file_download_from_string('Lorem ipsum dolor', 'test.txt');			// download string as a file
 echo $SOW->gzip('path/of/file.txt', 'dest/to/file.gz', 'w'); 				// create a gzip file. zip type: w / w9
 $SOW->file_write('test.txt', "Lorem ipsum dolor sit amet\n", 'a'); 			// create a file ('a' = append , 'w' = write, one line)
 echo $SOW->file_read('test.txt', false); 										
 var_dump($SOW->file_read('test.txt', true)); 						// second param: true = return as array each line from the file