SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist Maujor's Avatar
    Join Date
    Mar 2005
    Location
    Rio de Janeiro - Brazil - South America
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Code for comments doesn't work in IE

    A- Scenario
    1-) I've an Article Page with a link for Comments that sends to a form Page for fills the name, email url and comment.
    2-) When you submmit the form you'll be sent back to the Article Page and the new comment appear there.
    ---------------------------------------------------------------
    B- Problem
    My code doesn't works in Internet Explorer!
    ---------------------------------------------------------------
    C- See the problem in action in the following link: http://www.maujor.com/temp/article.php
    ---------------------------------------------------------------
    D- The relevant PHP code
    For the Article's Page:
    PHP Code:
    <?php
    $page 
    $_SERVER['REQUEST_URI'];
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <?php
    $articleID 
    "1";
    ?>
    <head>
    ............
    </head>
    <body>
    <h1>Article's Page</h1>
    <p>This is the article's text:......</p>
      

    <?php
        
    echo "<p><a href='add_comment.php?id=".$articleID."&amp;page="$page ."'>";
        echo 
    "Link for comments form page";
        echo 
    "</a></p> \n";
    ?>


    <table>
    Table for visitors comments
    </table>
    </body>
    </html>
    The form's Page:
    PHP Code:
    <?
    header
    ("Location: " $_POST['page']);
    ?>
    <!DOCTYPE .....
    <html>
    <head>........</head>
    <body>
    <h1>:: Your comment is welcome!::</h1>
    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" name="commentForm" id="commentForm">
    <fieldset>
    ...fields for name, email, url and textarea for comment...
    <input name="frmArticleID" type="hidden" id="frmArticleID" value="<?php echo $_GET['id']; ?>" />
    <input name="page" type="hidden" id="page" value="<?php echo $_GET['page']; ?>" />
    <p><input type="submit" name="Submit" value="Add Comment" class="botao"/>
    </p>
    </fieldset>
    </form>
    </body> 
    </html>
    Mauricio Samy Silva
    http://www.maujor.com/

  2. #2
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure it will make a difference, but one thing I notice is that in your <a> tag you're doing: <a href=''></a> when it should be <a href=""></a>.

  3. #3
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a RewriteCond %{HTTP_USER_AGENT} somewhere, maybe in a .htaccess file or in your httpd.conf file? Or maybe a getenv('HTTP_USER_AGENT'); in PHP code somewhere?

    Edit:

    Actually, just saw the header("Location: line ... see what musher says below and you'll want to add exit; after the header line.

  4. #4
    SitePoint Zealot musher's Avatar
    Join Date
    Nov 2005
    Location
    Hull, England
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to

    PHP Code:
    if (isset($_POST['page'] && $_POST['page']!=""
    {
    header("Location ".$_POST['page']);
    exit;

    Good point with 'exit' mark

  5. #5
    SitePoint Evangelist Maujor's Avatar
    Join Date
    Mar 2005
    Location
    Rio de Janeiro - Brazil - South America
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello;

    Musher: Great man! You had catch the error. Your code works fine! Thanks.
    Only for a minor and irrelevant missed ')' here => if (isset($_POST['page']) && ...
    ----------------------------------------------------------------------------
    LemoNade: I can't see where in my code you catched it. Thanks for your kindness.
    ----------------------------------------------------------------------------
    Mark1999: Yes, Mushes solves! Thanks for take your time.
    ----------------------------------------------------------------------------
    Problem solved!
    Many thanks.
    Now I'm going ahead with the code.
    Mauricio Samy Silva
    http://www.maujor.com/

  6. #6
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Maujor
    Hello;

    Musher: Great man! You had catch the error. Your code works fine! Thanks.
    Only for a minor and irrelevant missed ')' here => if (isset($_POST['page']) && ...
    ----------------------------------------------------------------------------
    LemoNade: I can't see where in my code you catched it. Thanks for your kindness.
    ----------------------------------------------------------------------------
    Mark1999: Yes, Mushes solves! Thanks for take your time.
    ----------------------------------------------------------------------------
    Problem solved!
    Many thanks.
    Now I'm going ahead with the code.

    Line 19 on the articles page

    Although if its working I guess it doesn't matter.

  7. #7
    SitePoint Evangelist Maujor's Avatar
    Join Date
    Mar 2005
    Location
    Rio de Janeiro - Brazil - South America
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello Masher,
    Why an exit; line?.
    The code is working fine without that line. (It seems that you edit the post and add that line. I'm right?)
    Mauricio Samy Silva
    http://www.maujor.com/

  8. #8
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without the exit; there's no guarentee the script will stop processing at that point. The exit; makes sure the script redirects and ends processing.

  9. #9
    SitePoint Evangelist Maujor's Avatar
    Join Date
    Mar 2005
    Location
    Rio de Janeiro - Brazil - South America
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by markl999
    Without the exit; there's...
    .
    But it seems that in the context of the code, the if statement is always false and
    only IE needs the if for work.
    Or I'm missing something?
    ------------------------------------------------------------------------
    I've hosted a test page (comments working) here:http://www.maujor.com/tutorial/comentarios.php
    The page is in portuguese, but I think that there will be no language troubles for post your feedback comment there, and see the script in action.
    Mauricio Samy Silva
    http://www.maujor.com/

  10. #10
    SitePoint Zealot musher's Avatar
    Join Date
    Nov 2005
    Location
    Hull, England
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Before we added the conditional, your script was sending a header of

    Code:
    Location
    without the neccesary filename or '/', which Firefox and others probably ignore, whereas IE uses it and tries to go to the root of "http://www.maujor.com/temp/", hence why you saw the "Index of..." at the top of the page.

    The conditional is always false, unless the user posts your form. In this case, your script sends a redirect to the page they were on and then stops processing. Maybe it works without the 'exit;' but it's best practice to put it in for a number of reasons. Unfortunately people like me easily forget, but that's what people like Mark are here for


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
  •