Skip to main content

Posts

Showing posts with the label Php

What is the difference between session and cookie?

If you set the variable to " cookies ", then your users  will not have to log in each time they enter your community. The cookie will stay in place within the user’s browser until it is deleted by the user. But Sessions are popularly used, as the there is a chance of your cookies getting blocked if the user browser security setting is set high. If you set the variable to "sessions", then user activity will be tracked using browser sessions, and your users will have to log in each time they re-open their browser. Additionally, if you are using the "sessions" variable, you need to secure the " sessions " directory, either by placing it above the web root or by requesting that your web host make it a non-browsable directory. The Key difference would be cookies are stored in your hard disk whereas a session aren't stored in your hard disk. Sessions are basically like tokens, which are generated at authentication. A session is available as ...

Php sessions

Before you can store user information in your PHP session, you must first start up the session. Note : The session_start() function must appear BEFORE the <html> tag. <?php session_start(); // store session data $_SESSION['views']=1; ?> <html> <body> <?php //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> </body> </html>  Destroying a Session <?php unset($_SESSION['views']); ?>    You can also completely destroy the session by calling the session_destroy() function:     <?php session_destroy(); ?> 

Php Cookies

first of all what is the need of cookie ? Why we use cookie ? Lets discuss it. With the use of POST and GET method we can fetch the data which is transfer from previous page , but suppose we want that data in all pages of my site mean throughout the site then ? Then the solution is Cookie. When you create a cookie, using the function setcookie, you must specify three arguments. These arguments are setcookie (name, value, expiration):   name : The name of your cookie. You will use this name to later retrieve your cookie, so don't forget it!   value : The value that is stored in your cookie. Common values are username(string) and last visit(date).   expiration :   The date when the cookie will expire and be deleted. If you do not set this expiration date, then it will be treated as a session cookie and be removed when the browser is restarted. Setcookie <?php    //Calculate 60 days in the future //seconds * minutes * hours * days + current ...

Date formats in php

Sometimes we need to display date in our comment , post , news etc. For that as you aware we need to store that date in our database , the format of date in database is Y M D. But that might be possible in some cases we need to display the date in different format. One simple way for that is explode the date which is come from database by "-" and set according to your requirement. But what happen when we want to display date in different format like 1 jan 2011 01 january  2011 01 january 11 etc... The solution is  strtotime . To display simple date in php echo date("Y-m-d"); but when date comes from database at that time use : date("j M Y ", strtotime( Here date comes form database  )); j M Y is different types of format ..More formats are display below :: Day d : Day of the month with leading zeroes. Values are 01 through 31. j : Day of the month without leading zeroes. Values 1 through 31 D : Day of the week abbreviations. ...

Find extension of file in Php

In our scripting sometimes we need to upload such documents , at that time there should be a validation for proper file. For example in your system suppose there is a field for image upload , that is obvious in that field only image formats are allowed (jpg,jpeg,png,gif etc.). At that time you have to give a validation on that field. In Php to find the extension and validation here is your code :  <?php                     $image = $_FILES["file"]["name"];    // to fetch the file name             $n1=strripos($image,".");                     // to find the last position of "."             $v1 =substr($image,$n1);                  ...

Find the difference between array

Sometimes we need to find the difference between arrays In php there is a inbuilt function to find the difference between array. For example : <?php $a1=array(0=>"Apple",1=>"Honda",2=>"Scoda"); $a2=array(3=>"Scoda",4=>"Honda",5=>"Ford"); print_r(array_diff($a1,$a2)); ?>  The output of the code above will be:  Array ( [0] => Apple ) 

Difference between == and === in php

Two of the many comparison operators used by PHP are '==' (i.e. equal) and '===' (i.e. identical). The difference between the two is that '==' should be used to check if the values of the two operands are equal or not. On the other hand, '===' checks the values as well as the type of operands. Let me explain more using some examples: '==' (Equal): if("22" == 22) echo "YES"; else echo "NO";      The code above will print "YES". The reason is that the values of the operands are equal. Whereas when we run the example code below: '===' (Identical): if("22" === 22) echo "YES"; else echo "NO"; The result we get is "NO". The reason is that although values of both operands are same their types are different, "22" (with quotes) is a string while 22 (w/o quotes) is an integer. But if we change the code above to t...

Change port in Wamp server

Difference Between $ and $$ When you face the problem that Wampserver is not working or localhost is not working. There mainly because of three reason Namely : i) When in your system Skype (some application which use same port) is running ii) In your system IIS is running iii) For any other reason confliction We will sort out it one by one.   1) When in your system skype (some application which use same port) is running , Aassume in your  system  skype is running at that time first start your wamp after that start your skype   then both will work.       It is because skype use either port 80 or 443 .       If you dont want to do each and every time just follow the steps for permanent solution     i) Open skype ->> select tools ->> option     ii) Now click on advanced and in advance connection . You can find a checkbox Use po...

Difference Between $ and $$ in php

Difference Between $ and $$ Difference Between $ and $$ As you all know how can we declare simple kind of variable in php . $sign + name of your variable =  value that you want to assign to that variable . For example : $test = "testing continue"; $create = "world"; But now lets look at the use of $$ sign in php First lets take an example  : $create = "world"; $$create = "India"; This variables are same as $create = "world"; $world = "india"; In short  echo   $create  $($create); and  echo  $create $world; are same .. Enjoy…...

Difference between get and post and request

Fundamental Difference is probably the Visibility  - GET request is sent via the URL string (appended to the URI with a question-mark as separator), which is visible whereas POST request is encapsulated in the body of the HTTP request and can't be seen. Length  - Since, GET request goes via URL, so it has a limitation for its length. It can't be more than 255 characters long (though this is browser dependent, but usually the max is 255 characters only). Whereas no such maximum length limitation holds for the POST request for the obvious reason that it becomes a part of the body of the HTTP request and there is no size limitation for the body of an HTTP request/response. Performance  - GET request is comparatively faster as it's relatively simpler to create a GET request and the time spent in the encapsulation of the POST request in the HTTP body is saved in this case. In addition, the maximum length restriction facilitates better optimization of GET implem...

Difference between Echo and Print in php

Difference Between $ and $$   print  and  echo  are commands used to output information to the visitors screen (on the web page). Both do the same job, so it usually comes down to a matter of personal preference on which one you like to use.  <?php print  "Hello World! <br />"; echo  "Hello World!"; ?> The output : Hello World! Hello World! The above example shows both outputs are the same. It also shows that regular HTML tags may be placed within the value areas as well as regular text.  There is a slight difference between print and echo which would depend on how you want to use the outcome. Using the print method can return a true/false value. This may be helpful during a script execution of somesort. Echo does not return a value, but has been considered as a faster executed command. All this can get into a rather complicated discussion, so for now, you can just use whichever one you prefer.  Some r...

Create Master pages using PHP and Dreamweaver

Connecting to MySQL Database

PHp session and cookies

Php mail function

Configure Xampp server

Basic Ajax example

Jquery Ajax and php intro

Php Basic Intro

Validation of email in php

    Validation of email address in php function is_valid_email ( $email ) { $result = TRUE ;   if (! eregi   (" ^[_a-z0-9-]+( \. [_a-z0-9-]+)*@[a-z0-9-]+( \. [a-z0-9-]+)*( \. [a-z]{2,4})$ ", $email ))   { $result = FALSE ; } return $result ; } Use this function and pass the email address which you get from the your field.... :)