Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP Switch/Case and the Dreaded Unclean URLs

  • This topic is empty.
Viewing 15 posts - 16 through 30 (of 64 total)
  • Author
    Posts
  • #128821
    CrocoDillon
    Participant

    Change `switch ($_GET) {` to `switch ($_SERVER) {`

    If that doesn’t work try `var_dump($_SERVER)` and see what you get.

    #128823
    rpotterjr
    Participant

    No change…

    #128824
    CrocoDillon
    Participant

    So, what did `var_dump` get you?

    #128825
    rpotterjr
    Participant

    Nothing different. I tried restarting the server and clearing browser cache…

    No change..

    #128826
    rpotterjr
    Participant

    I was at this stage before without the Virtual Server by specifying the root in php, but couldn’t ever get past this problem…

    #128828
    CrocoDillon
    Participant

    Put `var_dump($_SERVER)` in you index.php file (before the switch), and show me what it gives with and without the .htaccess file.

    #128829
    Argeaux
    Participant

    Maybe you have to enable mod_rewrite in your apache install.

    #128830
    rpotterjr
    Participant

    I have mod_rewrite enabled. As for the var_dump($_SERVER), nothing is different. Just back at square one again…

    #128831
    CrocoDillon
    Participant

    Nothing is different doesn’t give me much info to work with.

    #128832
    rpotterjr
    Participant

    I can make the var_dump($_SERVER)

    before the switch/case in a separate statement, but all that does is display a count of the character length of each link clicked.

    #128833
    rpotterjr
    Participant

    The address changes through:

    rpotterjr.dev/about

    and

    rpotterjr.dev/contact

    However, the content stays stuck on the home page’s content.

    If I revert back to not having the rewrite, I can navigate from page to page changing the content, but the address displays as http://rpotterjr.dev/index.php?page=about. This is with or without var_dump($_SERVER)

    #128834
    rpotterjr
    Participant

    So here is my code currently:

    .htaccess
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?$1 [NC,L]

    #128835
    rpotterjr
    Participant

    PHP case/switch

    $_GET = null;

    switch ($_GET) {

    case “portfolio”:
    include(‘theme/default/pages/portfolio.php’);
    break;

    case “resume”:
    include(‘theme/default/pages/resume.php’);
    break;

    case “about”:
    include(‘theme/default/pages/about.php’);
    break;

    case “contact”:
    include(‘theme/default/pages/contact.php’);
    break;
    // Default Page
    default:
    include(‘theme/default/pages/home.php’);
    break;
    }

    ?>

    #128836
    rpotterjr
    Participant
    #128837
    CrocoDillon
    Participant

    The I guess QUERY_STRING just reads the URL instead of using the internal rewriting. Try `var_dump($_GET)` (with .htaccess) to see if the ‘page’ key (it won’t be called page unless you change the .htaccess file) is in there. If it is, you can use something like `if (isset($_GET)) {…}` etc.

Viewing 15 posts - 16 through 30 (of 64 total)
  • The forum ‘Back End’ is closed to new topics and replies.