Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: header problem

  1. #1
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default header problem

    Hi guys,

    I think my script is right but my host say its wrong...

    can you find an issue?

    PHP Code:
    $URL='QUERY_STRING';

    <p>The query string is: <?php echo $_SERVER[$url]; ?></p> 

    <p>Filename: <? echo $_GET['filename'?></p> 
    $url="www.en4cer.co.uk/downloads/".$url
    header ("Location: $URL");

    <html>
    <title>Ades Design</title>
    <head></head>
    <body>
    </body>
    </html>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I can find several.
    $URL='QUERY_STRING';
    This code is outside a PHP block, so will be printed, not executed. Also, setting it to the static value 'QUERY_STRING' seems useless to me. I would suspect that you meant $_SERVER['QUERY_STRING'].
    <p>The query string is: <?php echo $_SERVER[$url]; ?></p>
    Variable names are case-sensitive. You defined $URL, not $url. The paragraphs are also outside an HTML body.
    <p>Filename: <? echo $_GET['filename'] ?></p>
    You haven't actually done anything with this, but it sounds dangerous, since it implies that you're going to allow the client to pass you a filename without doing any validation on it.
    $url="www.en4cer.co.uk/downloads/".$url
    Here you define $url, but since $url currently isn't defined, $url is 'www.en4cer.co.uk/downloads/'. Since it's to be passed as a header, this should be a full URL, including protocol. Also, you missed a semicolon.
    header ("Location: $URL");
    Equivalent to:
    Code:
    header ('Location: QUERY_STRING');
    <html>
    <title>Ades Design</title>
    <head></head>
    <body>
    </body>
    </html>
    No DOCTYPE was provided, the title should be inside the head, and you're still in PHP parsing mode. Also, this code will never (or should never) be read. I suppose it's not a bad idea to provide something for unusual clients, though, even if those clients don't support HTTP fully.
    Code:
    <?php
      $url = 'http://www.en4cer.co.uk/downloads/' . $_SERVER['QUERY_STRING'];
      header("Location: $url");
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
        <title>Ades Design</title>
      </head>
      <body>
        <p>
          Warning: your browser does not support
          HTTP correctly.  It is likely that a large portion
          of the Web will be broken for you.
        </p>
        <p>
          You should have been sent to <a href="<?php print $url; ?>"><?php print $url; ?></a>.
        </p>
      </body>
    </html>
    Last edited by Twey; 12-13-2006 at 03:52 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ah, hang on....

    Ok, the script is

    PHP Code:
    <?
    $URL
    ='QUERY_STRING'

    <
    p>The query string is: <?php echo $_SERVER[$url]; ?></p>  

    <p>Filename: <? echo $_GET['filename'?></p>  
    $url="www.en4cer.co.uk/downloads/".$url 
    header ("Location: $URL"); 
    ?>
    <html>
    <title>Ades Design</title>
    <head></head>
    <body>
    </body>
    </html>

    this document is called downloads.php, and i go to downloads.php?file=8

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's still wrong. Use the one I posted above.
    header ("Location: $URL");
    I forgot to mention that this won't work, since you've already sent output.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Created a new document using your template above, but it doesnt work.. http://www.en4cer.co.uk/downloads2.php?file=8

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It was a complete script, not a template. Nevertheless, are you certain there was no whitespace before the opening <?php? If there were, the script would fail to work.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    I suppose it's not a bad idea to provide something for unusual clients, though, even if those clients don't support HTTP fully.
    There are some lingering HTTP/1.0 user agents, so yes, the HTTP/1.1 recommendations should be followed and certain redirections should be accompanied by a hypertext link. It's not that difficult: the markup you posted could be included in an include file. However, one should avoid mentioning technical details - especially when what you've written isn't necessarily correct - and just request that the user follow the link.

    Mike

  8. #8
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    It was a complete script, not a template. Nevertheless, are you certain there was no whitespace before the opening <?php? If there were, the script would fail to work.
    sorry, i meant script.. deff no white space, certain

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by mwinter
    There are some lingering HTTP/1.0 user agents
    Surely they don't send an Host header, and so are completely broken on the Web of today?
    deff no white space, certain
    No text of any kind? No linebreaks, spaces, tabs, DOCTYPEs?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    Surely they don't send an Host header, and so are completely broken on the Web of today?
    No, not all. Some implemented the Host header as an extension so they can just about manage. NN4, for example.

    Mike

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
  •