trial post

asjhasjhasda

Advertisements

An intro to php

Introduction

  • The PHP programming language is a server-side HTML embedded scripting language.
  • PHP stands for PHP: Hypertext Preprocessor.PHP is free and is an open source software product.
  • The PHP scripts are executed on the server.
    PHP supports many databases (MySQL, Sybase, Oracle and many others.)
  • PHP runs on different platforms (Unix, Linux, Windows.)
    PHP is compatible with almost all web-servers used today (Apache, IIS, etc.)
  • A PHP file can contain plain text, HTML tags and scripts
    The PHP files can have one of the following extensions: php, php3 or phtml.

Basic Syntax

Its nothing but simple html, inside the body PHP scripting block is placed beginning with <?php and ending with ?>. The only new thing is the ‘echo’ statement. The echo function will print everything on the screen that is placed between “”
<html>
<head>
</head>
<body>
<?php echo “Hello World, this is my first PHP program!” ?>
</body>
</html>

This code will print Hello World, this is my first PHP program!

Variable declaration

<?php
$my_variable = 20;
$my_variable2 = “Hello World”;
?>

As in C,C# etc. string functions,arithmetic, assignment, logical operations all can be performed.

The Control Statements, if, else if, while, do, for loop all have similar structure as that in other languages like C,C#.

Quick demos can be illustrated as:

if – else block

<?php
$var=1;
if($var == 2) {
echo “The if statement is true”;
} else {
echo “The if statement is not true”;
}
?>

for loop

<?php
for ($x=0; $x<=5; $x++)
{
echo “Number is ” . $x . “<br />”;
}
?>

while loop

<?php
$x=0;
while($x<=5)
{
echo “The number is ” . $x . “<br />”;
$x++;
}
?>

Functions

Pretty much similar execution and logic when compared to other languages 🙂

html>
<body>

<?php
function myFunction()
{
echo “black”;
}

echo “My car has the color “;
myFunction();
?>

</body>
</html>

output – My car has the color black

Functions with arguments can be illustrated as :

<?php
function ourFunction($x)
{
echo $x . “.<br />”;
}

$y = “black”;
echo “My car color is “;
ourFunction(“white”);

echo “My car color is “;
ourFunction (“$y”);
?>

Output will be like:
My car color is white.

My car color is black.

 

include and require functions – As name suggests, include will include the specified php file while execution and require refers that, in order the code to execute,it requires the specified file, if the specified file doesn’t exist, the execution will break.

Simple example will make it clear 🙂

Let the header.php be a file  having a simple echo statement “yahoo”

<html>
<body>

<?php include(“header.php”); ?>
<p>Some example text!</p>

</body>
</html>

Output of this code will be like:

yahoo

Some example text!

where as if header.php file doesn’t exist,

<html>
<body>

<?php
require(“header.php”);
echo “Just some random text!”;
?>

</body>
</html>

Will result in error and the execution will be stopped and hence the echo statement is never executed.

 

This is just a basic intro to php language 🙂

Microsoft Cortana – speech based search now possible with Windows 10. !

You can now search by saying the keyword, Windows 10 comes up with Microsoft Cortana as their default search. We can also use it for normal search (by typing the keywords).

In Windows 10, search is placed in the task bar itself,

Capture

 

 

 

You have to  log in to Cortana with your Microsoft account for using this speech based search, but anyone can make use of normal search with Cortana.

Here are some screenshots(took from phone) of using speech based search using Microsoft Cortana.

IMG_20150506_115346221                       IMG_20150506_144325107

Normal search will look like,

IMG_20150506_115405721_HDR

Have fun 🙂

API and HTTP Requests

The HTTP stands for HyperText Transfer Protocol. HyperText is text with links in it and a transfer protocol is a fancy way of saying “rules for getting something from one place to another. We can use HTTP to grab information from just about any web page on the Internet. The Internet is full of clients who ask for various resources (web pages, files, and so on), and servers, who store that information (or know where to get it).

When you make an HTTP request, it zips through the Internet until it finds the server that knows how to fulfill that request. Then the server sends a response back to you. In fact, this client/server relationship is a prerequisite of a set of principles called REST (Representational State Transfer).
An API, or application programming interface, is kind of like a coding contract: it specifies the ways a program can interact with an application.

How to make a request ?

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.facebook.com/", false); // more details on open method.
xhr.send();
console.log(xhr.status); //returns 200 - HTTP STATUS code for success.
console.log(xhr.statusText); // returns OK

The number of HTTP methods are:

  • GET: retrieves information from the specified source.
  • POST: sends new information to the specified source.
  • PUT: updates existing information of the specified source.
  • DELETE: removes existing information from the specified source.

An HTTP request is made up of three parts:

The request line, which tells the server what kind of request is being sent (GET, POST, etc.) and what resource it’s looking for;
The header, which sends the server additional information (such as which client is making the request)
The body, which can be empty (as in a GET request) or contain data (if you’re POSTing or PUTing information, that information is contained here).

Endpoints are API-defined locations where particular data are stored. If you’re using the API for a video hosting service, there might be endpoints for the most popular videos, the most recent videos, etc.

Authentication & API Keys

Many APIs require an API key.an API key identifies you to the API, which helps the API provider keep track of how their service is used and prevent unauthorized or malicious activity. Some APIs require authentication using a protocol called OAuth. API keys are often long alphanumeric strings.

eg: var apiKey = “FtHwuH8w1RDjQpOr0y0gF3AWm8sRsRzncK3hHh9”;

HTTP Status Codes

A successful request to the server results in a response, which is the message the server sends back to you, the client. The response from the server will contain a three-digit status code. These codes can start with a 1, 2, 3, 4, or 5, and each set of codes means something different.

1xx: You won’t see these a lot. The server is saying, “Got it! I’m working on your request.”

2xx: These mean “okay!” The server sends these when it’s successfully responding to your request.

3xx: These mean “I can do what you want, but I have to do something else first.” You might see this if a website has changed addresses and you’re using the old one; the server might have to reroute the request before it can get you the resource you asked for.

4xx: These mean you probably made a mistake. The most famous is “404,” meaning “file not found”: you asked for a resource or web page that doesn’t exist.

5xx: These mean the server goofed up and can’t successfully respond to your request.

More  information on HTTP Status codes – here.

Structure of a Response

  • A response line, which includes the three-digit HTTP status code.
  • A header, which includes further information about the server and its response.
  • The body, which contains the text of the response.

Response can be obtained either as XML or JSON, we need to parse the corresponding response for the actual data retrieval.

Contact form plugin used – Contact Form-7 

If you wish to re-direct to a confirmation/thank you page after submitting the contact form, follow the below steps:

1)Go to Contact from the dashboard menu

2) Scroll down to ‘Messages’ section, here , under the ‘Sender’s message was sent successfully’ you will see the current message displayed on submitting a form successfully, what you need to do is, delete entire text from there.

contact

3) Scroll down further to ‘Additional Settings’ section, and add this piece of code there, this is the link of the page to which redirection has to be done.
on_sent_ok: "location = 'http://www.mywebsite.com/thankyou/';"

4)Save the contact form and now you will be redirected to a new page on successful submission.

We can give custom structure for our posts.

Go to [Settings -> Permalinks]

customi

In the custom structure, You can specify the structure u want to follow.

My default structure was – http://www.mywebsite.com/%year%/%month%/%day%/%psotname% and i  want my posts to be in a customized manner, prefixing /blog/. Now customized post structure looks like – http://www.mywebsite.com/blog/%year%/%month%/%day%/%psotname%.

If you are using any custom content types for posts, then the there is a chance  of permalinks getting broken as this customized structure affects to all posts type, so to handle this scenario, we need to add this piece of code to the register_post_type method,

'rewrite' => array('slug' => 'custom-post-name', 'with_front' => FALSE)

Not yet completed, we then need to got to [Settings -> Permalinks] and click on save, then only the change will reflect. 🙂

Custom flappy bird game

Click here for playing custom game i made.

edit code here and make yours. 🙂

Super-Mario-no-longer-the-007

 

Code:

index.html

<!DOCTYPE html>
<html>
<head>
<title>Super Mario!</title>
<link rel=’stylesheet’ type=’text/css’ href=’stylesheet.css’/>
<script type=’text/javascript’ src=’script.js’></script>
</head>
<body>
<img src=”http://i1061.photobucket.com/albums/t480/ericqweinstein/mario.jpg”/&gt;
</body>
</html>

stylesheet.css

img {
position: relative;
left: 0;
top: 0;
}

script.js

$(document).ready(function() {
$(document).keydown(function(key) {
switch(parseInt(key.which,10)) {
// Left arrow key pressed
case 37:
$(‘img’).animate({left: “-=10px”}, ‘fast’);
break;
// Up Arrow Pressed
case 38:
$(‘img’).animate({top: “-=10px”}, ‘fast’);
break;
// Right Arrow Pressed
case 39:
$(‘img’).animate({left: “+=10px”}, ‘fast’);
break;
// Down Arrow Pressed
case 40:
$(‘img’).animate({top: “+=10px”}, ‘fast’);
break;
}
});
});

 

Tag Cloud