Download presentation
Presentation is loading. Please wait.
1
Some HTTP Examples
2
A utility which shows all data from incoming requests is here: http://www.cs.ucc.ie/j.bowen/cs3314/resources/showRequest.php It is defined as follows: <?php echo " SERVER variables: "; foreach ($_SERVER as $name => $value) { echo "$name = $value "; } echo " GET variables: "; foreach ($_GET as $name => $value) { echo "$name = $value "; } echo " POST variables: "; foreach ($_POST as $name => $value) { echo "$name = $value "; } echo " COOKIE variables: "; foreach ($_COOKIE as $name => $value) { echo "$name = $value "; } ?>
3
A program which delivers a web-page in the user’s preferred language http://www.cs.ucc.ie/j.bowen/cs3314/resources/multiLingual.php It is defined as follows: <?php function answerInEnglish() {?> Hello <?php } function answerInFrench() {?> Bonjour <?php } function giveDefaultAnswer() {?> Default greeting <?php } $language=$_SERVER['HTTP_ACCEPT_LANGUAGE']; if ($language=='en-ie') { answerInEnglish(); } else if ($language=='fr') { answerInFrench(); } else { giveDefaultAnswer(); } ?>
4
Consider this page: http://www.cs.ucc.ie/j.bowen/cs3314/resources/poem.html It is defined as follows: <?php function answerInEnglish() {?> Hello <?php } function answerInFrench() {?> Bonjour <?php } function giveDefaultAnswer() {?> Default greeting <?php } $language=$_SERVER['HTTP_ACCEPT_LANGUAGE']; if ($language=='en-ie') { answerInEnglish(); } else if ($language=='fr') { answerInFrench(); } else { giveDefaultAnswer(); } ?>
5
Consider this web-page http://www.cs.ucc.ie/j.bowen/cs3314/resources/poem.html It contains the following: Wordsworth I wandered lonely as a cloud That floats on high o'er vales and hills
6
When we try to view this page, we see this, because the tags in the file are not recognized
7
Now consider this file, which has a different name but contains exactly the same text: http://www.cs.ucc.ie/j.bowen/cs3314/resources/poem.xml It contains the following: Wordsworth I wandered lonely as a cloud That floats on high o'er vales and hills
8
When we try to view this page, we see this, because the tags in the file are treated as XML tags
9
See what happens when we use telnet to access the poem.html file The response message contains this header line: Content-Type: text/html
10
See what happens when we use telnet to access the poem.xml file The response message contains this header line: Content-Type: text/xml
11
The different behaviour shown by a browser when we view the two files poem.xml and poem.html is caused by these two different headers The header Content-Type: text/html tells the browser to treat the data in the body of the response message as a HTML file The header Content-Type: text/xml tells the browser to treat the data in the body of the response message as a XML file
12
Consider this PHP program which outputs the XML for the poem http://www.cs.ucc.ie/j.bowen/cs3314/resources/poem1.php It contains the following: <?php echo “ ”; echo “ Wordsworth ”; echo “ ”; echo “ I wandered lonely as a cloud ”; echo “ That floats on high o'er vales and hills ”; echo “ ”; ?>
13
When we try to view this page, we see this, because the tags in the file are not recognized
14
Let’s use telnet to try to view the same page Notice that the response message contains the header Content-Type: text/html This is why the browser did not recognize the tags
15
Now consider this PHP program which outputs a header before it outputs the XML text for the poem http://www.cs.ucc.ie/j.bowen/cs3314/resources/poem2.php It contains the following: <?php header(“Content-Type: text/xml”); echo “ ”; echo “ Wordsworth ”; echo “ ”; echo “ I wandered lonely as a cloud ”; echo “ That floats on high o'er vales and hills ”; echo “ ”; ?>
16
Let’s use telnet to ask for the page created by this new PHP program Notice that the response message contains the header Content-Type: text/xml This means that a browser should recognize that the tags are XML tags
17
When this page in a browser, the browser does indeed recognize that the tags are XML tags
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.