SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru dwzemens's Avatar
    Join Date
    Mar 2005
    Location
    United States
    Posts
    768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simpleton Alert!!! "Please answer easy question"

    I have a tiered menu system that I am trying to implement. Each page must send a variable that then calls the appropriate include file later in the code. I am REALLY new to this PHP stuff, and I can't get the syntax right:

    Here is the <a href> that calls:
    test.php?content_id=124&amp;cat=which_menu.php

    I aquire the variable via: $cat = $_GET['cat'];

    In the page, I just want to call the an include file based on the $cat variable. I have tried many syntax combinations, and have not gotten it to work. Here is my last try:

    <?php "'include'.'$cat'"; ?>

    Can anyone tell me what the syntax would be? Thanks very much, once again!

  2. #2
    SitePoint Enthusiast aLargeTrout's Avatar
    Join Date
    Sep 2005
    Location
    Bucharest, Romania
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got this right, you would have to use
    PHP Code:
    include($cat); 
    But note that this is a VERY INSECURE method. You could try maybe something like:

    PHP Code:
    if($cat=='somevalue'){
      include(
    'somefile.php');


  3. #3
    SitePoint Guru dwzemens's Avatar
    Join Date
    Mar 2005
    Location
    United States
    Posts
    768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks bigfish....

    Can you tell me what the security issue is?

  4. #4
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    North America
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...(I'm not bigfish but...) ...the security issue has to do with someone hi-jacking your include file without the variable $cat existing.

    I'm not overly familiar with this but that's what I do know.

  5. #5
    SitePoint Guru dwzemens's Avatar
    Join Date
    Mar 2005
    Location
    United States
    Posts
    768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it. Well, in this situation, the include file simply is a list of my menu items - easier to keep in one place and pass on, etc. No secrets here. Unless I am missing something else?

  6. #6
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    North America
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Generally I use these techniques just for good practice and form so I don't forget

  7. #7
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     if(isset($cat)){ 
         require_once( 
    $_GET['cat']); 

    Use require_once to avoid duplication errors

  8. #8
    SitePoint Enthusiast aLargeTrout's Avatar
    Join Date
    Sep 2005
    Location
    Bucharest, Romania
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •