Tuesday, July 20, 2010

How Can I Learn PHP ?

Learning PHP is easy and hard. Now we’ll see both easy sides and hard sides.
If you learnt a programming language, c/c++ is very simple for you. But if you not, you should learn programming logic.
If you don’t know something about algorithms, you should start to learn something about it because every programming logic has got algorithms logic. And also PHP has got same logic.
You can visit some visual education sites for learning PHP. But this can’t be enough for learning. This could be good for basis education.
Hard sides for learning are:
If you are not doing this job fondly, this job is hard.
If you don’t know anything about programming, this job is hard.
If you don’t have a target, this job is hard.
But beating these difficulties on your hand. You have to practice, making some scenarios and solve them for learn PHP better.
Most importantly, if you love programming, there is no difficulty for you!

Thursday, July 15, 2010

Obtaining Source Code Of Site With PHP

Obtaining source code with php is very simple. We can easily find source code of site with file_get_contents function. We can make this like that:

file_get_contents("address of site");

$site=file_get_contents("http://coderfunctions.blogspot.com");

echo "$site"; //we can show source code of site with code of print code.

But when we take a print of code, scanner will interpret these codes and source codes can’t display on internet page. In order to see this code, you should save these files like txt.

Tuesday, July 13, 2010

Array Functions (PHP)

I will describe some functions, while we can use it in working with Array.
count(x) = If we write a sequence of variable for x, it will count how many element is in this sequence.
For Example:
$a[4]=10;
$number=count($a);
It will show us how many elements is in this ($a) sequence.
array_pop($sequence) = it is take off the last element of $sequence sequence.
For Example:
$a=array('a','b','c');
echo array_pop($a);
//## c will be in output of this code. It will give to us a last element of this sequence.
array_push($sequence,"elements ") = It is using for adding new elements to the end of the sequence.
For Example:
$a=array("a","b","c");
array_push($a,"d","f");
//## This code add ”d” and “f” to the end of the sequence.

Friday, July 9, 2010

Who Are Coming to Our Site And Where Are They Coming From ?

We sometimes wonder where our visitors or members are coming from and we want to learn where they are coming from. Because of this, we’ll reach this information with php by using some function.
$_SERVER['HTTP_REFERER'] = We can reach visitors address, if they reach our site with clicking the link.
For Example, we can use this codes for learning some information about our visitors or members which are click our link from google :
$referer = strtolower($_SERVER['HTTP_REFERER']);
//If there is a google term, it means it is coming from google,
if(strpos($referer,"google")){
echo $referer;
}
There is 2 more codes and these are string codes:
strtolower= It maximize phrase’s size which is string code.
strpos($stringvariable, “word or letter which will search”)= This code is using for searching variable in string.
If we use these codes like that, we can’t see where are they coming from. We have to save information to database for reach them. In this way, we can only see visitors information.

Monday, July 5, 2010

Function of PHP Exit and Die

Mission of this functions is ended working programs. The biggest difference between die function and exit is you can show a message when a program ended by die function.

For Example:
<?php

if($a==10)
{
die("Program was ended");
} else
{
echo "program is continueing"
}


?>


In here, program will be ended because of $a=10 and it will bring string from function of die. If we want to make same example in exit :

<?php


$a=10;
 if($a==10)
{
echo "Program was ended";
 exit();
} else{

echo "Program  is continueing." ;
}

?>


As you see, we have to write echo function. For this reason, we prefer die function. For example, if you have a problem in connection to database, you can show a warning message and you can stop the connection.

Function of PHP echo() ;

Writing " hello world " in firsth function is a classic. As you know, PHP is a programing language which is using on server base. In echo scanner (firefox, Ie etc.), this function is good for writing variable in echo.

For Example :

<?php

   echo  "HELLO WORLD!!";

?>



If you want yo can write in more than one line.

<?php
echo "Such a
       nice
                   day ";


?>


And best part of echo function, you can use html tags in echo.

<?php
echo "HELLO WORLD!!//
next line ";


?>

The last type of using is very helpful in some situations. For example, you'll view a saved file from database, you can list them with html tags.

Friday, July 2, 2010

Environmental Variables (SERVER FUNCTIONS)

CONTENT_LENGTH : It takes information about POST method from FORM.

DOCUMENT_ROOT : It keeps path.

HTTP_COOKIE : It is variable which keeps cookies .

HTTP_HOST : Host name or Host adress .