Page 219 - Open Soource Technologies 304.indd
P. 219

Unit 9: Web Techniques



            value=”<?=$varMovie;?>” />                                                            Notes
                                 </p>
                                 <p>
                                         <label for=’formName’>What is your name?</label><br/>
                                         <input type=”text” name=”formName” maxlength=”50”
            value=”<?=$varName;?>” />
                                 </p>
                                 <p>
                                         <label for=’formGender’>What is your Gender?</
            label><br/>
                                         <select name=”formGender”>

                                                <option value=””>Select...</option>
                                                <option value=”M”<? if($varGender==”M”) echo(“
            selected=\”selected\””);?>>Male</option>
                                                <option value=”F”<? if($varGender==”F”) echo(“
            selected=\”selected\””);?>>Female</option>
                                         </select>
                                 </p>
                                 <input type=”submit” name=”formSubmit” value=”Submit” />
                          </form>
            <p>
            <a href=’http://www.html-form-guide.com/php-form/php-form-processing.html’
            >’PHP form processing’ book page</a>
            </p>


            </body>

            </html>
            9.5 Setting Response Headers


            As we have  already discussed, the HTTP response that a server sends back to a client contains
            headers that identify the type of content in the body of the response, the server that sent the
            response, how many bytes are in the body, when the response was sent, etc. PHP and Apache
            normally  take  care  of  the  headers for  you,  identifying  the  document  as  HTML,  calculating
            the length  of the HTML page,  and so on. Most web  applications never need to set headers
            themselves. However, if you want to send back something that’s not HTML, set the expiration
            time for a page, redirect the client’s browser, or generate a specific HTTP error, you will need
            to use the header( ) function.
            The only catch to setting headers is that you must do so before any of the body is generated.
            This means that all calls to header ( ) (or setcookie( ), if you are setting cookies) must happen
            at the very top of your file, even before the <html> tag. For example:

            <?php header(‘Content-Type: text/plain’); ?> Date: today From: fred To: barney Subject: hands
            off! My lunchbox is mine and mine alone. Get your own, you filthy scrounger!




                                             LOVELY PROFESSIONAL UNIVERSITY                                   213
   214   215   216   217   218   219   220   221   222   223   224