This method should also work on servers behind a load balancer: $isSecure = false; if (isset($_SERVER[’HTTPS’]) && $_SERVER[’HTTPS’] == ‘on’) { $isSecure = true; } elseif (!empty($_SERVER[’HTTP_X_FORWARDED_PROTO’]) && $_SERVER[’HTTP_X_FORWARDED_PROTO’] == ‘https’ || !empty($_SERVER[’HTTP_X_FORWARDED_SSL’]) && $_SERVER[’HTTP_X_FORWARDED_SSL’] == ‘on’) { $isSecure = true; }$isSecure = false; if (isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] == ‘on’) { $isSecure =
Continue reading PHP: check if SSL is being used
Category: phpsnippet
Check if an file exists on the remote server
// Check if an file exists on the remote server // CURLOPT_NOBODY: don’t download content $url = ‘http://www.domain.com/file.jpg’; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if (curl_exec($ch) !== FALSE) { // Remote file exist } curl_close($ch) ;// Check if an file exists on the remote server //
Continue reading Check if an file exists on the remote server
PHP: Output a snapshot of all defined variables
Simply input the snippet below into any PHP file and you’ll get a browser-friendly snapshot of all variables defined in the current scope. This is especially handy in larger systems like WordPress or Smarty where a needed value may already be defined by the system but you have no way of knowing the variable’s name.
Continue reading PHP: Output a snapshot of all defined variables
PHP: trim a string and add a delimiter without breaking words
/** * Trim a string and add a delimiter without breaking words * * @param string $string string to trim * @param integer $width character count to trim * @param string $delim delimiter. Default: ‘…’ * @return string processed string **/ function trim_string($string, $width, $delim=’…’) { // Remove any newline and carriage return characters $string
Continue reading PHP: trim a string and add a delimiter without breaking words
PHP: get the request method
This snippet can be used to get the request method: switch ($_SERVER[’REQUEST_METHOD’]) { case ‘GET’: $params = empty($_GET) ? null : $_GET; break; case ‘POST’: $params = empty($_POST) ? null : $_POST; break; }switch ($_SERVER[‘REQUEST_METHOD’]) { case ‘GET’: $params = empty($_GET) ? null : $_GET; break; case ‘POST’: $params = empty($_POST) ? null : $_POST;
Continue reading PHP: get the request method