Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    switch :: case :: break

    I'm using this method. It is too large to put in this thread, so I have attached it. View the image first, then look at my code and repost here. Thanks for your help!!!
    Attached Files Attached Files
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    And your question is?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My question is in the attached file.....
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    and what if I don't wanna look in the attached file for the question? Hmmmm?


    You should post the question in the post so people can see what the question is and figure out if they can help without having to download the file and then unzip it.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heres my question.

    I have code that is in the attached file....

    It is using a switch and then case break. Which works like
    http://mydomain.com/category.php?cat=home

    which includes the file /includes/home.html

    My code is not working so If you would, analyze it and tell me what is wrong with it. Thanks. The code is in the attachment of my very first post. Thanks very much for everyones help
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,096
    Thanks
    11
    Thanked 101 Times in 99 Posts
    the issue is probably the fact that you have the default : case first , it should come last after everything else.

    but aside from that , save yourself some code and ...

    PHP Code:
    <?
    $file 
    '/home/user/public_html/includes/' $_GET['cat'] . '.html' ;
    if( 
    file_exists$file ) ){
       include 
    $file ;
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #7
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Firepages, could you tell me what that code does? Like in line by line process?

    Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,096
    Thanks
    11
    Thanked 101 Times in 99 Posts
    ...
    PHP Code:
    <?
    /*
    build a path to the file you want to grab based on your $_GET['cat'] variable eg if blah.com?cat=yaks
    then $file translates to 
    '/home/user/public_html/includes/yaks.html'
    */

    $file '/home/user/public_html/includes/' $_GET['cat'] . '.html' ;

    /*
    see if yaks.html actually exists
    */

    if( file_exists$file ) ){

    /*
    if it does include it
    */

       
    include $file ;
    }else{

    /*
    else include a default or sorry page
    */

     
    include '/home/user/public_html/includes/sorry.html' ;

    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the code!

    So I changed my file to this
    PHP Code:
    <?php
    $file 
    '/home/user/public_html/includes/' $_GET['cat'] . '.html' ;
    if( 
    file_exists$file ) ){
       include 
    $file ;
    }
    else{
    include 
    '/home/user/public_html/includes/sorry.html' ;
    }
    ?>
    and I get this error
    Code:
    Warning: SAFE MODE Restriction in effect. The script whose uid is 10323 is not allowed to access /home owned by uid 0 in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/category.php on line 3
    
    Warning: Unable to access /home/user/public_html/includes/sorry.html in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/category.php on line 7
    
    Warning: Failed opening '/home/user/public_html/includes/sorry.html' for inclusion (include_path='.:/usr/local/psa/apache/lib/php') in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/category.php on line 7
    Whats up?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You don't have home/user/public_html

    Your server is set up as /usr/local/psa/home/vhosts/net-riches.com/httpdocs/

    Reading the errors are helpful

    Just change delete the /home/user/public_html and point to the include files like you would in your normal way.

  • #11
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, that compressed some of my errors.

    Now I get this
    Code:
    Warning: open_basedir restriction in effect. File is in wrong directory in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/category.php on line 7
    
    Warning: Failed opening 'includes/sorry.html' for inclusion (include_path='.:/usr/local/psa/apache/lib/php') in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/category.php on line 7
    with this PHP
    PHP Code:
    <?php
    $file 
    'includes/' $_GET['cat'] . '.html' ;
    if( 
    file_exists$file ) ){
       include 
    $file ;
    }
    else{
    include 
    'includes/sorry.html' ;
    }
    ?>
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #12
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try using ./includes/

  • #13
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks acecool, but that didn't work....still getting
    Code:
    Warning: Unable to access ./includes/sorry.html in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/category.php on line 7
    
    Warning: Failed opening './includes/sorry.html' for inclusion (include_path='.:/usr/local/psa/apache/lib/php') in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/category.php on line 7
    Firepages, Spookster, Nightfire??? Know my problem??
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #14
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your script is located in includes/category.php. Apparently you just haven't got a directory named 'includes' in that directory, that's where your error comes from. Does it work if you just include 'sorry.html'?

    And now to something completely different: Don't let this script run on your webhost as it is now. It's a security hole. Anyone can pass an arbitrary path to a file which will be included and, depending on the nature of the file, eventually sent to the browser. That's probably not what you had in my mind, but you're opening doors for an attacker quite wide. You need to clean the path string from unwanted chars like ../, . and the like. Or use an array as a lookup table in which all alllowed paths are stored.
    De gustibus non est disputandum.

  • #15
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I don't think that matters. I got my script running correctly and thats all that I care about.....
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •