webdesign

JS Redirection – IOS – Android

JS Redirection – IOS – Android

Create in the same folder:
– mobile-detector.html
It this the javascript that detects the device type
– ios.html
The page for IOS devices
– android.html
The page for Android devices
– error.html
An Error page

mobile-detector.html


<!DOCTYPE html>
<html>
<head>
 
<script type="text/javascript">
// #######################################################
// Mobile JS Redirect
// Don't Break My b***s - Gimme Code! Project                                           
// Author: Andrea Tonin - http://blog.lucedigitale.com                                 
// This code come with absolutely no warranty                                            
// If you use this code in your project please give a link to http://blog.lucedigitale.com 
// Thanks in advance                                                                       
// #######################################################
 
var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        },
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i);
        },
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        },
        Opera: function() {
            return navigator.userAgent.match(/Opera Mini/i);
        },
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
        }

    };



if ( isMobile.Android() ) {
        document.location.href = "android.html";
    }
else if(isMobile.iOS())
	{
	document.location.href="ios.html";
	}
else
    {
    document.location.href="error.html";
    }
 
</script>
 
</head>
 
<body>
<center>
<br>
<b><h1>You are being redirected to other site.</h1>
<br>
<br>
<h1>If you are not redirected within 4 seconds</h1></b>
<br>
<h1><a href="android.html">ANDROID HERE</h1></a>
<h1><a href="ios.html">IOS HERE</h1></a>
</center>
</body>
 
</html>

ios.html


<!DOCTYPE html>
<html>
 
<head>
</head>
 
<body>
<!-- Questo è un commento, non viene renderizzato dal browser -->
<h1>IOS!</h1>
</body>
 
</html>

android.html


<!DOCTYPE html>
<html>
 
<head>
</head>
 
<body>
<!-- Questo è un commento, non viene renderizzato dal browser -->
<h1>Android!</h1>
</body>
 
</html>

error.html


<!DOCTYPE html>
<html>
 
<head>
</head>
 
<body>
<!-- Questo è un commento, non viene renderizzato dal browser -->
You need an Android or IOS device!
</body>
 
</html>

By |JavaScript, Web Design|Commenti disabilitati su JS Redirection – IOS – Android

.htaccess – Snippets

.htaccess – Snippets

What is .htaccess?
.htaccess is a configuration file for use on web servers running the Apache Web Server software.

When a .htaccess file is placed in a directory which is in turn ‘loaded via the Apache Web Server’, then the .htaccess file is detected and executed by the Apache Web Server software.

If you use a local Windows OS, you need:

1.Create a .txt file ‘name.htaccess’, write the code
2.Upload to a Apache Server
3.Rename it inside the server to ‘.htaccess’ (without name), using your sFTP program.

NOTICE: Windows OS does not allow a file without a name!

Folder Password Protection

Create .htpasswd
/home4/lucedigi/.htpasswd

NOTICE: The best way is to create .htpasswd outside the public folder (usually www)


myusername:mypassword

Create .htaccess in
/home4/lucedigi/public_html/blog/wp-admin/.htaccess


AuthType Basic
        AuthName "Restricted Area"
        AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"
        require valid-user

The protection is limited to the folder where .htaccess is installed

File Protection

Create .htpasswd
/home4/lucedigi/.htpasswd


myusername:mypassword

Create .htaccess in
/home4/lucedigi/public_html/blog/wp-admin/.htaccess


AuthType Basic
        AuthName "Restricted Area"
        AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"
        require valid-user

<Files "mypage.html">
  Require valid-user
</Files>

mypage.html and .htaccess have to be installed in the same folder!

For file list protection:


         <FilesMatch "(secure\.html)|(secure\.txt)">
          AuthType Basic
          AuthName "Restricted Area"
          AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"
          Require valid-user
        </FilesMatch>

Blocking Requests from Particular User Agents


RewriteEngine On  
RewriteBase /  
SetEnvIfNoCase Referer "^$" bad_user
SetEnvIfNoCase User-Agent "^badbot1" bad_user
SetEnvIfNoCase User-Agent "^badbot2" bad_user
SetEnvIfNoCase User-Agent "^badbot3" bad_user
Deny from env=bad_user

Blocking Requests from Particular User Agents

You need to have mod_rewrite enabled


<IfModule mod_rewrite.c>
 
RewriteEngine on
 
RewriteCond %{HTTP_REFERER} bannedurl1.com [NC,OR]
 
RewriteCond %{HTTP_REFERER} bannedurl2.com [NC,OR]
 
RewriteRule .* - [F]
 
</ifModule>

Changing a Default Index Page


DirectoryIndex mypage.html

404 Redirect


# 404 Redirect

ErrorDocument 404 http://www.lucedigitale.com

By |Web Design|Commenti disabilitati su .htaccess – Snippets

PHP – MYSQL – Insert Records

PHP – MYSQL – Insert Records

I Records sono le righe della tabella.

Syntax:

INSERT INTO table_name
VALUES (value1, value2, value3,…)

or

INSERT INTO table_name (column1, column2, column3,…)
VALUES (value1, value2, value3,…)

<?php
// Create connection
// Statement: mysqli_connect(host,username,password,dbname)
// NOTICE: se lo script è installato nello stesso server del Data Base, host->localhost
$con=mysqli_connect("localhost","lucedigi_user","mypassword","lucedigi_testphp");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
else
  {
  echo "Great! Connect to MySQL!";
  }
// Aggiungere nuovi record alle colonne - START
// Statement:
// INSERT INTO table_name (column1, column2, column3,...) 
// VALUES (value1, value2, value3,...)
mysqli_query($con,"INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin',35)");

mysqli_query($con,"INSERT INTO Persons (FirstName, LastName, Age) 
VALUES ('Glenn', 'Quagmire',33)");
echo "Great! New Record Inserted!"; 
// Aggiungere nuovi record alle colonne - END

mysqli_close($con); 
echo "Great! Connection Closed!"; 
?>

phpMyAdmin Dashboard:

mysql-0003

By |MySQL, PHP, Web Design|Commenti disabilitati su PHP – MYSQL – Insert Records

PHP – Basic Structure

PHP – Basic Structure

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

PHP code are executed on the server, and the result is returned to the browser as plain HTML.

In PHP, all user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are case-insensitive.

However; in PHP, all variables are case-sensitive.

PHP files have extension “.php”

The official PHP website is: http://www.php.net

<!DOCTYPE html>
<html>
<body>

<?php

// This is a one-line c++ style comment

# This is a one-line shell-style comment

/* This is a multi line comment
yet another line of comment */

echo "Hello World!";
?>

</body>
</html>

Notice:
The PHP code is tagged inside:

<?php
... your php code ... ;
?>

or with the short notation
<?
... your php code ... ;
?>

By |PHP|Commenti disabilitati su PHP – Basic Structure

Beautiful CSS Table

Beautiful CSS Table. Beautiful CSS/HTML Table – Ready to Use Code!

By |CSS, Web Design|Commenti disabilitati su Beautiful CSS Table