Skip to content

Instantly share code, notes, and snippets.

View helquisson's full-sized avatar

Hélquisson Dourado helquisson

View GitHub Profile
<?php
function verifyServerOnLine($server, $port)
{
$response = false;
$fp = fsockopen($server, $port, $errno, $errstr, 3);
if (!$fp) {
throw new \Exception('Erro: nenhum servidor encontrado!');
} else {
<?php
// texto padrão
$text = 'texto padrão';
// senha
$password = 'admin123';
// nomes
$nomes = array('joão', 'maria', 'josé');
@helquisson
helquisson / dig_cpf.php
Created October 30, 2014 01:24
Calcula digito verificador de cpf
<?php
/**
* Calcula digito verificador de CPF
* @author Hélquisson Dourado
*/
function calcDigVerifCPF($num) {
@helquisson
helquisson / fibonacci.php
Last active August 29, 2015 14:08
Sequência de Fibonacci
<?php
function fib($num) {
$i = 1;
$j = 0;
for($k=0;$k<$num;$k++) {
$t = $i + $j;
$i = $j;
$j = $t;
<?php
header( 'Content-type: text/html; charset=utf-8' );
echo 'Resposta em:';
echo '<br/><br/>';
$i = 10;
while ($i > 0) {
echo $i;
flush();
ob_flush();
sleep(1);
@helquisson
helquisson / send.php
Last active August 29, 2015 14:05
exemplo phpmailer com anexo
<?php
include_once 'PHPMailer/class.phpmailer.php';
if( filter_has_var(INPUT_POST, 'enviar') ) {
$arquivo = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
$dir = 'upload/';
move_uploaded_file($arquivo, $dir.$name);
@helquisson
helquisson / session.php
Last active August 29, 2015 14:02
Exemplo de $_GET e $_SESSION
<?php
session_start(); //iniciar sessão
// cria variável de array se ainda não existir
if ( !isset($_SESSION['produto']) ) {
$_SESSION['produto'] = array();
}
// adiciona produtos ao array
if ( isset($_GET['prod']) ) {