Skip to content

Instantly share code, notes, and snippets.

AddDefaultCharset utf-8
RewriteEngine on
RewriteBase /
RewriteRUle ^(.*)$ index.php
@nikolaykrylov
nikolaykrylov / site_visits_counter.php
Last active March 10, 2017 20:56
Counts how many times user visited site (using cookies)
<?php
$count = 1;
if (isset($_COOKIE['counter'])){
$count = intval($_COOKIE['counter']);
$count ++;
}
setcookie('counter', $count);
@nikolaykrylov
nikolaykrylov / lesson_9_1.php
Last active March 10, 2017 17:20
Why cookie doesn't expire if I refresh page?
<?php
setcookie("user", 'something', time() + 3);
if (isset($_COOKIE['user'])){
echo "Wellcome, friend!";
}
else echo "Wellcome, guest.";
?>
@nikolaykrylov
nikolaykrylov / newboston_connect.inc.php
Created February 27, 2017 12:44
Login\logout wiht data grabbing from different fields
<?php //connect.inc.php
$conn_error = 'Could not connect.';
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_connect = @mysqli_connect($mysql_host, $mysql_user, $mysql_pass);
$mysql_db = 'a_database';
if(!@mysqli_connect($mysql_host, $mysql_user, $mysql_pass) || !@mysqli_select_db($mysql_connect, $mysql_db))
{
die($conn_error);
<?php //connect.inc.php
$conn_error = 'Could not connect.';
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_connect = @mysqli_connect($mysql_host, $mysql_user, $mysql_pass);
$mysql_db = 'a_database';
if(!@mysqli_connect($mysql_host, $mysql_user, $mysql_pass) || !@mysqli_select_db($mysql_connect, $mysql_db))
{
die($conn_error);
@nikolaykrylov
nikolaykrylov / connect.php
Last active February 18, 2017 20:01
Write from form to database
<?php
require 'login.php';
$con = mysqli_connect($db_hostname, $db_username, $db_password, $db_database);
mysqli_set_charset($con, "utf8");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL:" . mysqli_connect_error();
}
function heightDetect() {
$(".main_head").css("height", $(window).height());
};
heightDetect();
$(window).resize(function() {
heightDetect();
});