About server scripts and browser scripts

Source: Internet
Author: User
Tags send cookies
About server scripts and browser scripts & nbsp; & nbsp; web & nbsp; I know this is a problem 2. please do not give me any further advice. & Nbsp; I think browser scripts, such as javascript, are interpreted and executed by the browser. Server Scripts are Server Scripts and browser scripts.
I know this question very well. please kindly advise me.

In my opinion, browser scripts, such as javascript, are interpreted and executed by the browser. The server script is executed by the server, such as PHP.
In the W3C PHP Tutorial, I also said:

Reference
You cannot view the source code of PHP in the browser by viewing the source document-you can only view the output of the PHP file, that is, pure HTML. This is because the script has been executed on the server before the result is returned to the browser.


In my understanding, php is used to generate an html page. when the browser accesses the page, it generates a page and then gives it to the browser. This php task is complete. Or php is over here.


However, PHP can operate on cookies. are cookies not in the browser.

I analyzed the possible situation, that is, the page generated by php uses javascript or something similar to this operation. But you are not sure. please advise.
------ Solution --------------------
Understanding is basically correct. Php can read and write client cookies through the http header.
When you access a website through a browser, an http request is actually sent. The request header contains the cookie on the client. The cookie on your machine is sent to the server in this way. you can understand the server as a php script. After the php script completes processing the request and is interpreted as html, it will return http response, which will return the html and cookie that have been interpreted to the client machine. In this way, php can read and write cookies on your machine.

There are many things in an http interaction. The following describes the http interaction process of Baidu. You can see what the request and response interact.

Request headers
---------------------------------
Request URL: http://www.baidu.com/
Request Method: GET
Status Codes: 200 OK
Request Headersview source
Accept: text/html, application/xhtml + xml, application/xml; q = 0.9, */*; q = 0.8
Accept-Charset: GBK, UTF-8; q = 0.7, *; q = 0.3
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN, zh; q = 0.8
Cache-Control: max-age = 0
Connection: keep-alive
Cookie: BAIDUID = response: FG = 1; bd1__firstime = 1357125911300; BDUSS = response; BDUT = response; PMS_Cache = 1358090765568; BDRCVFR [feWj1Vr5u3D] = I67x6TjHwwYf0;


Response header
------------------------
Cache-Control: private
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 8379
Content-Type: text/html; charset = utf-8
Date: Sat, 19 Jan 2013 21:55:43 GMT
Expires: Sat, 19 Jan 2013 21:55:43 GMT
Server: BWS/1.0.
Set-Cookie: H_PS_PSSID = 1792_1421_1760_1788; path =/; domain = .baidu.com
Vary: Accept-Encoding
------ Solution --------------------
LZ understands it very well. it is a step forward than many people in this version who ask "how to assign javascript values to php variables" (which I did not mean by BS, at least I know that php is running over and cannot be stopped. this is a relatively advanced topic and requires further research.

When I was doing js, I realized that some things had to be done on the server. I came into contact with the name of server side javascript (the above thinking occurred during this period) and found that there was very little support, discover php again, so as to embark on the php path

The http header mentioned above, I suggest you understand it from now on. in the past, there was no assistance. it was difficult to understand it by reading a book. but The Times are different, nowadays, many tools (and simple tools) can capture packets. packet capture is not difficult. in my early years, I still thought it was something hackers did and laughed. I installed a firebug plug-in firefox, or chrome has similar functions (or chrome may be simpler)

An http process is like this, and the connection is omitted. you can learn socket or capture the web page and then learn about tcp connections. just talk about the data transmission part --
1. client requests, such as accessing a Web site: the data sent at this time is not just a Web site, but a bunch of request header information. the request header information contains methods (GET, POST ......) + Website, website host + Port, accessed software and version, transmission mode (compression or not), language, and others, add the get or post data. For more information, see the example above and RFC2616 of the http protocol, cookie information may also be added (these are basically completed by the browser)
2. the server returns data after processing: the returned data is not only a webpage (or file), but also a bunch of header information, the first line is the status (only one status). 200 indicates that a success is returned, 404 indicates that a failure is found, and 500 indicates a server problem. for more status numbers, refer to the protocol documentation; then there are other data types, such as the returned data type. text/html is of course html; Expiration Time, transmission method ...... All of the above are automatically completed by web servers (such as apache), but can also be changed through php. Cookie is to load this header, and the php header function is to change the above content, but the session and cookie are extracted separately for programming. After the return header ends, it is the "formal" transmission content, such as the webpage and the image itself.

Understanding this helps you to use the header function and handle other things. for example, you need to know why a header function should be sent before the output after drawing a graph in php and why the session should be placed at the beginning of the program, how does php output xml, how does php Cache or not cache a page ...... And so on

Javascript can also send cookies, which is irrelevant to php sending cookies, but because they are all cookies, the next request sent by javascript can also be read by php. this raises a topic, cookies written by any other software or program can also be read by the server. so study other topics.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.