Professional Web Applications Themes

PHP scripts and IE - PHP Development

Hi Guys Using WinXP Pro SP2 with PHP 5.0.2, MySQL4.0.21 and Apache 2.0.52. I am just trying to get to grips with these tools and am following a book PHP, MySQL and Apache All in One from SAMS publishing. Everything seems to be working OK except when I am trying out some simple PHP form scripts. I click the send button and I get a File Download dialog asking me if I want to open or save the file. Why does it do this? The html file is as follows <html> <head> <title>A Simple HTML form</title> </head> <body> <form action="send_simpleform.php" ...

  1. #1

    Default PHP scripts and IE

    Hi Guys
    Using WinXP Pro SP2 with PHP 5.0.2, MySQL4.0.21 and Apache 2.0.52. I am
    just trying to get to grips with these tools and am following a book PHP,
    MySQL and Apache All in One from SAMS publishing.
    Everything seems to be working OK except when I am trying out some simple
    PHP form scripts. I click the send button and I get a File Download dialog
    asking me if I want to open or save the file. Why does it do this?

    The html file is as follows
    <html>
    <head>
    <title>A Simple HTML form</title>
    </head>
    <body>
    <form action="send_simpleform.php" method="POST">
    <p><strong>Name:</strong><br>
    <input type="text" name="user"><br>
    <p><strong>Message:</strong><br>
    <textarea name="message" rows="5" cols="40"></textarea></p>
    <p><input type="submit" value="Send"></p>
    </form>
    </body>
    </html>

    and the php file is:
    <?php
    echo "<p>Welcome <b>$_POST[user]</b>!</p>";
    echo "<p>Your message is:<br><b>$_POST[message]</b></p>";
    ?>


    Thanks

    TJ

    --
    Thanks

    TJ


    Tony Guest

  2. #2

    Default Re: PHP scripts and IE

    Aaaah - it's an IE issue - works okay in Opera. Any ideas whyu it doesn't
    work in IE anyone?
    "Tony Wainwright" <net> wrote in message
    news:cth53g$sf0$btinternet.com... 


    Tony Guest

  3. #3

    Default Re: PHP scripts and IE

    Tony Wainwright scribbled something along the lines of: 

    File Download dialogs are usually triggered by unknown MIME-types (which
    can be manipulated within a PHP script with the Content-type header).
    Change the PHP file so it's content looks like this:

    <?php
    header('Content-type: text/html');
    ?>
    <html>
    <head>
    <title>A Simple PHP Script</title>
    </head>
    <body>
    <p>Welcome <b><?php echo $_POST['user']; ?></b>!</p>
    <p>Your message is:<br>
    <b><?php echo $_POST['message']; ?></b></p>
    </body>
    </html>

    Please note that strings are ALWAYS enclosed in 'single-quotes' (for
    literals) or "double-quotes" (for parsable strings). Otherwise you're
    implying they were the value of a constant. That also goes for strings
    that are indexes of associative arrays.

    All content outside the <?php ?> enclosed parts of a file will be
    treated as literals and not pd by PHP but printed as-is.


    In the long run you should find out why your page is not sent as
    text/html and fix it. Maybe your server is sending .html files by
    default as application/xhtml+xml, which would be correct for .xht and
    ..xhtml files but is usually inapropriate for .html and .htm files
    because that's the traditional extension for HTML files (standard or not).


    If that didn't fix it tho, I have no fscking idea.

    --
    Ashmo
    Ashmodai Guest

  4. #4

    Default Re: PHP scripts and IE

    I noticed that Message-ID: <cth53g$sf0$btinternet.com> from
    Tony Wainwright contained the following:
     


    /That/ is taken from a book?

    You need a better book...
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/
    Geoff Guest

  5. #5

    Default Re: PHP scripts and IE

    Sorry Geoff, just learning - if you could point out what is wrong with the
    code I would appreciate it. And perhaps suggest a better book (I am using
    PHP, MySQL and Apache All in One, published by Sams)

    TJ

    "Geoff Berrow" <co.uk> wrote in message
    news:com... 
    >
    >
    > /That/ is taken from a book?
    >
    > You need a better book...
    > --
    > Geoff Berrow (put thecat out to email)
    > It's only Usenet, no one dies.
    > My opinions, not the committee's, mine.
    > Simple RFDs http://www.ckdog.co.uk/rfdmaker/[/ref]


    Tony Guest

  6. #6

    Default Re: PHP scripts and IE

    How many groups did you post this on ????
    "Tony Wainwright" <net> wrote in message
    news:cth53g$sf0$btinternet.com... 
    dialog 


    Sal Guest

  7. #7

    Default Re: PHP scripts and IE

    Sal Perconte scribbled something along the lines of: 

    Two, it seems.

    By the way, top-posting makes Baby Satan cry.

    --
    Ashmo
    Ashmodai Guest

  8. #8

    Default Re: PHP scripts and IE

    Tony Wainwright scribbled something along the lines of: 

    In general everything by O'Reilly (company, not author) is great. Their
    books are quite exhaustive, but also well-written.

    If it looks spiffy and artsy and kinda like a boulevard magazine you
    should avoid it like the plague. Even though it'll look like it explains
    everything easily, it'll teach you bad habbits and wrong approaches and
    will only lead to problems in the long run (most web authors to date are
    unable to write real HTML).


    For PHP the reference at http://www.php.net is just perfect. It's got
    some great introductions and examples for nearly everything (if you look
    in the right place).

    You'll learn the little MySQL you need along the way. That's not too
    difficult. In extreme cases the reference at http://www.mysql.com tends
    to be somewhat of a help.

    For HTML I'd recommend that you get an introductionary book ("Dynamic
    HTML, The Definitive Guide" is a nice one which covers all of HTML as
    well as some CSS and JavaScript, both of which you'll bump into when
    you're tired of black text on white background).

    For Apache there's enough decent stuff on the net. Google is your friend.

    --
    Ashmo
    Ashmodai Guest

  9. #9

    Default Re: PHP scripts and IE

    I noticed that Message-ID: <cthahu$7gm$btinternet.com> from
    Tony Wainwright contained the following:
     

    Actually it's not bad enough to cause the error but I think it could
    lead you into bad habits. I find it easier to be consistent in my use
    of superglobals and use them like so :- $_POST['user']

    If you tried to do
    echo $_POST[user];
    You would get a warning notice. It only works in your case because it
    is contained within double quotes. I find it simpler to use just one
    way. Unfortunately this means you have to write the lines as:-

    echo "<p>Welcome <b>".$_POST['user']."</b>!</p>";
    echo "<p>Your message is:<br><b>".$_POST['message']."</b></p>";
    But it saves you having to think of whether to use single quotes or not.

    Also, it's a good idea to check if variables exist before using them. I
    know this script won't get called unless the POST variables exist, but
    again it's all about good habits.

    As for your original problem. Sorry, can't recreate it - it works fine
    in IE here.
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/
    Geoff Guest

  10. #10

    Default Re: PHP scripts and IE

    Geoff Berrow scribbled something along the lines of: 
    >
    >
    > Actually it's not bad enough to cause the error but I think it could
    > lead you into bad habits. I find it easier to be consistent in my use
    > of superglobals and use them like so :- $_POST['user']
    >
    > If you tried to do
    > echo $_POST[user];
    > You would get a warning notice. It only works in your case because it
    > is contained within double quotes. I find it simpler to use just one
    > way. Unfortunately this means you have to write the lines as:-
    >
    > echo "<p>Welcome <b>".$_POST['user']."</b>!</p>";
    > echo "<p>Your message is:<br><b>".$_POST['message']."</b></p>";
    > But it saves you having to think of whether to use single quotes or not.
    >
    > Also, it's a good idea to check if variables exist before using them. I
    > know this script won't get called unless the POST variables exist, but
    > again it's all about good habits.[/ref]

    Actually the most sensible code would be:

    echo '<p>Welcome <b>', $_POST['user'], '</b>!</p>';
    echo '<p>Your message is:<br>
    <b>', $_POST['message'], '</b></p>';

    Single quotes mean that the content will be printed as-is. Double quotes
    mean the content might contain magic (variables, etc) which should be
    pd. Also whitespace behaves differently from what you'd expect when
    you're using double quotes.
    Thus single quoted strings are processed faster.

    Using the dot operator leads to the string being combined before being
    echoed, the comma will lead to every single value being echoed on its
    own (as both things lead to the same output the latter should be
    preferred because it's faster).

    You should always check whether the array key exists before you use it
    (array_key_exists). Then you should usually perform a value check if
    you're going to do anything with it.

    Of course the best solution if you have lots of text to output is not to
    run the static part through PHP in the first place, so:

    <p>Welcome <b><?php echo $_POST['user']; ?></b>!</p>
    <p>Your message is:<br>
    <b><?php echo $_POST['message']; ?></b></p>

    would be the best solution IMO (although you might want to make it
    multilingual later on, but I won't go into that).

    --
    Ashmo
    Ashmodai Guest

  11. #11

    Default Re: PHP scripts and IE

    Check your apache and/or configuration(s). I believe that your problem
    may lie in the fact that your server is probably sending back a
    text/php or similar header. It should be sending back a text/html or
    similar.

    You really don't want to have to add the header to every PHP doent.

    I can't really be of help past there. Issue is probably in the php.ini,
    but I'm not sure.

    -Wes

    ncf Guest

  12. #12

    Default Re: PHP scripts and IE

    On Sun, 30 Jan 2005 01:31:28 +0000, Geoff Berrow <co.uk>
    wrote:
     
    >
    > Actually it's not bad enough to cause the error but I think it could
    > lead you into bad habits. I find it easier to be consistent in my use
    > of superglobals and use them like so :- $_POST['user']
    >
    > If you tried to do
    > echo $_POST[user];
    > You would get a warning notice. It only works in your case because it
    > is contained within double quotes. I find it simpler to use just one
    > way. Unfortunately this means you have to write the lines as:-[/ref]

    Unless I'm mistaken the original code actually won't work no matter what-
    surely the point was that
    echo " ... $_POST['user'] ... ";
    Should be
    echo " ... {$_POST['user']} ... ";
    .... Unless the output is meant to be '<p>Welcome <b>Array</b>!</p>' 

    Kelvin Guest

  13. #13

    Default Re: PHP scripts and IE

    I noticed that Message-ID: <opslma78o1z0l2a2snoopy> from Kelvin Mackay
    contained the following:
     
    >
    >Unless I'm mistaken the original code actually won't work no matter what -[/ref]

    You're mistaken. :-)

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/
    Geoff Guest

  14. #14

    Default Re: PHP scripts and IE

    You didn't setup Apache properly to tell it that PHP is a programming
    language and not a normal file on the server. Check your settings in
    the httpd.conf file regarding your PHP settings.

    Don Guest

  15. #15

    Default Re: PHP scripts and IE

    On Thu, 03 Feb 2005 21:48:40 +0000, Geoff Berrow <co.uk>
    wrote:
     
    >>
    >> Unless I'm mistaken the original code actually won't work no matter
    >> what -[/ref]
    >
    > You're mistaken. :-)
    >[/ref]

    How embarrassing - well you learn something new every day :)
    Kelvin Guest

  16. #16

    Default Re: PHP scripts and IE

    Don Wilson scribbled something along the lines of: 

    Uhm... No~oh?
    The server knows very well PHP files are supposed to be pd by PHP
    first, re-read the original post.

    However it apparently sends the wrong MIME-type (probably none specified
    in PHP's configuration and thus text/plain or some such).

    --
    Ashmo
    Ashmodai Guest

Similar Threads

  1. php scripts
    By Soc4me3 in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: August 15th, 06:37 PM
  2. CS: Scripts do not appear in Scripts menu
    By jlw99@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 3
    Last Post: May 18th, 04:49 PM
  3. scripts that control other scripts
    By kiaoraFiona webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 8
    Last Post: October 6th, 05:07 PM
  4. Scripts - Somebody know how to do this?
    By RC in forum PHP Development
    Replies: 1
    Last Post: July 15th, 05:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139