I Remember when i was a fresher and learning PHP had to go through many sites to come to a conclusion.!! Let me put all that search in just one GO ........
PHP is a very simple language...and learning is even more easier.
Some basic understandings and you are up and Running to build websites [:)].
To start with... lets go through some basic and important things you need to know before you start PHP.
We need to know some of the basic concepts like
- How does a end - to - end http request/response work. Having said HTTP is stateless i.e it does not remember its previous state (GAJINI).
Let me write things in step format to understand better.
1. User enters a sitename eg: gmail.com and presses enter.
2. The request goes to the server.
3. The server receives the request and sends the response. The response also contains the 'status code' , 'content-type' for the browser along with the unique identifier which will be sent each time some fuether correspondence with the same site is made. This identifier is used to identify whom to send the response to.
4. The response is then displayed to the user.
5. Next time user sends a request it will also include the same identifier sent before so the server knows that this is same user who has sent request before. Based on this identifier further processing is done.
Now, with the above steps comes into picture the "Cookies" , "Sessions".
- Cookies : These are stored at client side, which means that they are stored at a particular location on the computer the user uses. So these can be modified any time by the user. That is the reason why it is not safe to store secure information in cookies.
- Sessions : These are stored at server end, i.e they will be stored on server somewhere where the user will not have direct access to. So are more secure as compared to cookies.
So the basic question... will the sessions work if cookies are disabled on browser??
Answer is no and yes. No because the sessions will not work as they work with post since it will not receive the unique identifier to identify the user. Yes because to have this working we could send the identifier as a query string in the browser.
- Whether to use POST/GET when sending a request.
- POST request : This will be used when you have to send some secure information which you do not want anybody to alter with. This anybody here is a hacker or some person who acts as an intermediary and steals information.
eg: When sending username and password send it using POST since the information should not be stolen and altered in between.
POST is also used when you want to send large amount of information in the request.
- GET request : This will be used sending things that do not require any security.
eg: Sending page nos could be done using GET.
Mostly used when the amount of information sent is small. i.e you cannot be sending large data in the query string.
- Whether to use global variables
I would rather say no because global variables are like prostitutes and anybody could alter with in the code. So instead go with sessions.
- Buffering
PHP supports buffering. Advantage is it will help reduce the page load time. i.e we store the whole HTML in a variable and display all at once. instead of having load things slowly as parsing proceeds.
And last but not the least.....
PHP is an interpreted language... which means that when running it starts from the top of the page and proceeds line by line till the end of the page. And if any fatal error is encountered then execution stops there itself.
Do let me know if have missed out or you find some mistake in there....