• Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Legends: Z-A protagonist in the poll by clicking here.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Weird behaviour of a PHP Code

PoKeSaFaRi

Former PokemonSafari Webmaster
  • 370
    Posts
    21
    Years
    Hello. I'm experiencing an error on my webpage. The url is www.poke-safari.com

    When clicking any of the links, the content that it should load on the content area won't load, but instead it loads the same news area as in the main page.

    I've checked for quite a long time if the problem was the php code i was using, and ended up finding that's not the problem. I've been using the same php code for doing this for a while and I never experienced this problem before.

    I'm posting the code, just in case it can be helpfull to solve the problem:

    /********************* Content Starts Here ************************/
    if(strstr($ps, "..") || $ps[0]=="/") $ps = "";
    if(empty($ps)) $ps = "news.htm";
    else { $ps = $ps. ".htm"; }
    if(is_file("$ps")){ include("$ps");
    } else echo "<b>Se ha producido un error</b><br> Comunicaselo al webmaster cuanto antes para que lo pueda arreglar. Gracias";
    /******************** Content Ends Here *************************/

    I've tried it on my computer's home server to make sure it's not me. So maybe it's an error due to a wrong PHP instalation or an error of some kind.
     
    i had this same problem so i just deleted all the php code and links and re did it
     
    If it's not too much asking, what did u redo? The site's php into shtml?
     
    PHP:
    if (is_null($ps)){
         $ps="news.htm";
    } // end if
    
    if (is_file($ps)){
         include($ps);
    } // end if
    else{
         echo "\nCustom error message goes here.  \n<br>I do not speak Spanish; sorry.";
    } // end else

    .HTM is outdated unless you're using a system that doesn't recognise >3 characters for file extensions (i.e. the system is ancient -- win3.1).

    When I code, I'm a realist. If the file is empty, it really shouldn't be there. You have a lot of unnecessary code there, and it's formatted very inconsitently. Either use curly braces for all one-lined blocks following a for loop or if statement, or don't at all.
     
    Well, yeah.. maybe that coding isn't the best thing around, but that's the one I have been using for 3 years (or maybe more :P) and never had a problem with the HTM or that coding..

    I've tried replacing that code with some other PHP codes that do the same thing and none worked or solved the problem stated above....

    Suggestions anyone?
     
    PoKeSaFaRi said:
    Well, yeah.. maybe that coding isn't the best thing around, but that's the one I have been using for 3 years (or maybe more :P) and never had a problem with the HTM or that coding..

    I've tried replacing that code with some other PHP codes that do the same thing and none worked or solved the problem stated above....

    Suggestions anyone?
    Then, the rest of your code is doing it. You can't just meld a few pieces of code together, and expect them to work in tandem. It's best to just write something from scratch that works because you designed it.

    I other words, I need to see the all of the code of the page. Something else is at work here, or all the alternate codes you've been trying were rubbish.
     
    Alright, give me a second and I'll upload what I've been using as a template for 3yrs... I just don't get why it stopped working now, when it worked a month ago *shrugs*

    Link for the source (zipped file): https://www.poke-safari.com/index.zip

    If anyone wants to do a clean up of that code or optimize feel free to do so. I'll give credit, of course
     
    Did your host recently update the php to ver 5.0x? if so it may have broken your site...

    also:
    HellishHades said:
    PHP:
    if (is_null($ps)){
         $ps="news.htm";
    } // end if
    
    if (is_file($ps)){
         include($ps);
    } // end if
    else{
         echo "\nCustom error message goes here.  \n<br>I do not speak Spanish; sorry.";
    } // end else

    .HTM is outdated unless you're using a system that doesn't recognise >3 characters for file extensions (i.e. the system is ancient -- win3.1).

    When I code, I'm a realist. If the file is empty, it really shouldn't be there. You have a lot of unnecessary code there, and it's formatted very inconsitently. Either use curly braces for all one-lined blocks following a for loop or if statement, or don't at all.

    that code is NOT secure and will open him up to all kinds of abuse..

    i suggest:
    PHP:
    <?php
    if (!$ps) {
    $ps = "main";
    $include = $ps . ".html"; //use .txt or whatever
    }
    else {
    $include = $ps . ".html";
    }
    if (is_file($include) == "1") {
            include $include;
    }
    else {
    echo "\nCustom error message goes here.  \n<br>I do not speak Spanish; sorry.";
    } // end else (or use: include "404.html";)
    ?>
     
    Alright, I'll try that one PPN.

    By the way, thanks for this quick replies... hopefully i'll manage to get this problem sorted out soon :)
     
    PPN and I determined that it's not my code's fault (still it was helpful to see other php codes doing the same thing)

    I contacted my host as it's a PHP problem from the server. Thanks to y'all :)
     
    PPNSteve said:
    Did your host recently update the php to ver 5.0x? if so it may have broken your site...

    also:


    that code is NOT secure and will open him up to all kinds of abuse..

    Blah. I was thinking of compatibility issues with the restrictive filetype, but it shouldn't apply when the layout needs to be included.

    I'm 99% sure you don't need to reference the output of the is_file and related functions (i.e. is_file($var)==1), since they return boolean values for the if statement to process.

    PoKeSaFaRi said:
    PPN and I determined that it's not my code's fault (still it was helpful to see other php codes doing the same thing)

    I contacted my host as it's a PHP problem from the server. Thanks to y'all :)

    It seemed that way, since your over-all page code did not include any other embedded PHP code.

    It did have some external references, but I couldn't see those, anyway.
     
    It broke when Shawn's server updated PHP, which is why it broke on my site/domain and others too. Shawn gave me this new code to use: https://www.ryux.net/try.txt So if anyone else has that problem, try the new code. Worked for me.
     
    Back
    Top