SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_GET['topic'] an "Undefined Index"?

    I'm working on a CMS. Imagine a folder named Topics containing an index page named index.php. The mod-rewrite rules in my .htaccess file assign that folder/page the name "topic."

    I posted the following code in one of my top pages, to enable me to display and manipulated a page's URL.

    PHP Code:
    $MyURL = ($_GET['topic']);
    $MyURL rtrim($MyURL'/'); 
    If I'm viewing a dynamic page, like http://MySite/Topics/Mountains/, for example, then it works fine. But if I'm viewing the home page - http://MySite/Topics/ - then I get an error message, declaring "topic" an undefined index.

    It's not a major problem, as everything else still works, and it's a low-level error message that my visitors shouldn't see.

    But it kind of bugs me when I'm testing my pages. Anyway, is there some way to fix this "error," or to make the error message disappear? Thanks.

  2. #2
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just a shot in the dark, but try this :

    if(isset($_GET['topic'])) {

    $MYURL = rtrim($_GET['topic']);

    }


    or you could use @$MYURL = $_GET['topic'] to suppress the warning message.
    intragenesis, llc professional web & graphic design

  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by holmescreek View Post
    just a shot in the dark, but try this :

    if(isset($_GET['topic'])) {

    $MYURL = rtrim($_GET['topic']);

    }


    or you could use @$MYURL = $_GET['topic'] to suppress the warning message.
    The script didn't work, but I LOVE the @ sign idea. What a cool trick.

    Thanks for the tip.

  4. #4
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    @ is the worst idea ever. You shouldn't hide errors, you should fix them! Your original error is because the topic index in the _GET array doesn't exist. You need to always pass it, or code for when it isn't there.


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
  •