PHP versions and support by PHP Community

If your website is still running on legacy php version, you may consider to upgrade PHP version and your website’s source code to protect your website from future malware / malicious attack. The newer PHP version, the faster the performance, the more secure, and more efficient.

PHP 4: no longer supported by PHP Community
1&1 Extended Support available
PHP 5.2: no longer supported by PHP Community
1&1 Extended Support available
PHP 5.4: no longer supported by PHP Community
1&1 Extended Support available
PHP 5.5: no longer supported by PHP Community (since July 21st)
1&1 Extended Support available
PHP 5.6: support expected to end on Dezember 31, 2018
PHP 7: support expected to end on Dezember 03, 2018

To execute a function inside in external .js file

To execute a function inside in external .js file, use $( window ).load.
$(document).ready(function(){ is used to load .js file or loading js functions but those functions won’t be execute.

create set_user_status.js file, it looks similar to this:

function setUserStatus(v1,v2,v3){
    alert(v1+ v2+ v3);
    //or
    console.log(v1+ v2+ v3);
}

The header will preload the external .js file like this:

<script type="text/javascript" src="js/set_user_status.js"></script>

To execute the function setUserStatus inside the external .js file, use $( window ).load

$( window ).load(function() {//works
                setUserStatus( "value1", "value2", "value3");
            });

HTML5 Canvas Cheatsheet

  • HTML5 Canvas Element

    Html5 canvas element

    <canvas id="myCanvas" width="500" height="300">
    

    Html5 canvas element with fallback content

    <canvas id="myCanvas" width="500" height="300">
      your browser doesn't support canvas!
    </canvas>
    

    2d context

    var context = canvas.getContext('2d');
    

    Webgl context (3d)

    var context = canvas.getContext('webgl');
    
  • Shapes

    Draw rectangle

    context.rect(x, y, width, height);
    context.fill();
    context.stroke();
    

    Fill rectangle shorthand

    context.fillRect(x, y, width, height);
    

    Stroke rectangle shorthand

    context.strokeRect(x, y, width, height);
    

    Draw circle

    context.arc(x, y, radius, 0, Math.PI * 2);
    context.fill();
    context.stroke();
    
  • Styles

    Fill

    context.fillStyle = 'red';
    context.fill();
    

    Stroke

    context.strokeStyle = 'red';
    context.stroke();
    

    Linear gradient

    var grd = context.createLinearGradient(x1, y1, x2, y2);
    grd.addColorStop(0, 'red');   
    grd.addColorStop(1, 'blue');
    context.fillStyle = grd;
    context.fill();
    

    Radial gradient

    var grd = context.createRadialGradient(x1, y1, radius1, x2, y2, radius2);
    grd.addColorStop(0, 'red');
    grd.addColorStop(1, 'blue');
    context.fillStyle = grd;
    context.fill();
    

    Pattern

    var imageObj = new Image();
    imageObj.onload = function() {
      var pattern = context.createPattern(imageObj, 'repeat');
      context.fillStyle = pattern;
      context.fill();
    };
    imageObj.src = 'path/to/my/image.jpg';
    

    Line Join

    context.lineJoin = 'miter|round|bevel';
    

    Line Cap

    context.lineCap = 'butt|round|square';
    

    Shadow

    context.shadowColor = 'black';
    context.shadowBlur = 20;
    context.shadowOffsetX = 10;
    context.shadowOffsetY = 10;
    

    Alpha (Opacity)

    context.globalAlpha = 0.5; // between 0 and 1
    

  • Color Formats

    String

    context.fillStyle = 'red';
    

    Hex Long

    context.fillStyle = '#ff0000';
    

    Hex Short

    context.fillStyle = '#f00';
    

    RGB

    context.fillStyle = 'rgb(255,0,0)';
    

    RGBA

    context.fillStyle = 'rgba(255,0,0,1)';
    
  • Paths

    Begin Path

    context.beginPath();
    

    Line

    context.lineTo(x, y);
    

    Arc

    context.arc(x, y, radius, startAngle, endAngle, counterClockwise);
    

    Quadratic curve

    context.quadraticCurveTo(cx, cy, x, y);
    

    Bezier curve

    context.bezierCurveTo(cx1, cy1, cx2, cy2, x, y);
    

    Close Path

    context.closePath();
    
  • Images

    Draw Image with default size

    var imageObj = new Image();
    imageObj.onload = function() {
      context.drawImage(imageObj, x, y);
    };
    imageObj.src = 'path/to/my/image.jpg';
    

    Draw image and set size

    var imageObj = new Image();
    imageObj.onload = function() {
      context.drawImage(imageObj, x, y, width, height);
    };
    imageObj.src = 'path/to/my/image.jpg';
    

    Crop image

    var imageObj = new Image();
    imageObj.onload = function() {
      context.drawImage(imageObj, sx, sy, sw, sh, dx, dy, dw, dh);
    };
    imageObj.src = 'path/to/my/image.jpg';
    

  • Text

    Fill Text

    context.font = '40px Arial';
    context.fillStyle = 'red';
    context.fillText('Hello World!', x, y);
    

    Stroke Text

    context.font = '40pt Arial';
    context.strokeStyle = 'red';
    context.strokeText('Hello World!', x, y);
    

    Bold Text

    context.font = 'bold 40px Arial';
    

    Italic Text

    context.font = 'italic 40px Arial';
    

    Text Align

    context.textAlign = 'start|end|left|center|right';
    

    Text Baseline

    context.textBaseline = 'top|hanging|middle|alphabetic|ideographic
    |bottom';
    

    Get Text Width

    var width = context.measureText('Hello world').width;
    

  • Transforms

    Translate

    context.translate(x, y);
    

    Scale

    context.scale(x, y);
    

    Rotate

    context.rotate(radians);
    

    Flip Horizontally

    context.scale(-1, 1);
    

    Flip Vertically

    context.scale(1, -1);
    

    Custom Transform

    context.transform(a, b, c, d ,e, f);
    

    Set Transform

    context.setTransform(a, b, c, d ,e, f);
    

    Shear

    context.transform(1, sy, sx, 1, 0, 0);
    

    Reset

    context.setTransform(1, 0, 0, 1, 0, 0);
    
  • State Stack

    Push State onto Stack

    context.save();
    

    Pop State off of Stack

    context.restore();
    
  • Clipping

    Clip

    // draw path here
    context.clip();
    
  • Image Data

    Get Image Data

    var imageData = context.getImageData(x, y, width, height);
    var data = imageData.data;
    

    Loop Through Image Pixels

    var imageData = context.getImageData(x, y, width, height);
    var data = imageData.data;
    var len = data.length;
    var i, red, green, blue, alpha;
    
    for(i = 0; i < len; i += 4) {
      red = data[i];
      green = data[i + 1];
      blue = data[i + 2];
      alpha = data[i + 3];
    }
    

    Loop Through Image Pixels With Coordinates

    var imageData = context.getImageData(x, y, width, height);
    var data = imageData.data;
    var x, y, red, green, blue, alpha;
    
    for(y = 0; y < imageHeight; y++) {
      for(x = 0; x < imageWidth; x++) {
        red = data[((imageWidth * y) + x) * 4];
        green = data[((imageWidth * y) + x) * 4 + 1];
        blue = data[((imageWidth * y) + x) * 4 + 2];
        alpha = data[((imageWidth * y) + x) * 4 + 3];
      }
    }
    

    Set Image Data

    context.putImageData(imageData, x, y);
    
  • Data URLs

    Get Data URL

    var dataURL = canvas.toDataURL();
    

    Render Canvas with Data URL

    var imageObj = new Image();
    imageObj.onload = function() {
      context.drawImage(imageObj, 0, 0);
    };
    
    imageObj.src = dataURL;
    
  • Composites

    Composite Operations

    context.globalCompositeOperation = 'source-atop|source-in|source-out|source-over|destination-atop|destination-in|destination-out|destination-over|lighter|xor|copy';
    

Keyboard code “KeyCode” and how to use it in JavaScript

To work on HTML5 canvas to develop a tool similar to paint or free draw on an image, JQuery and Javascript are often used on the browser client side to perform simple tasks that would otherwise require a full postback to the server. There’re a set of keycode associated with each character on the keyboard.

To use this on your canvas on an html page, add JQuery and JavaScript to detect the key that user pressed as follow:

Key Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
a 65
b 66
c 67
d 68
 
Key Code
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
y 89
z 90
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
 
Key Code
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222
Include JQuery before the Script: https://code.jquery.com/jquery-3.1.1.min.js
$("#deletethis, body").keydown(function(e){
                if(e.keyCode == 46) {
                    alert('This object will be removed');

                    $("#deletethis").remove();
                }
               
               });

HTML section: