PHP Scripting Issue

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by harux10m, Sep 1, 2014.

  1. harux10m

    harux10m New Member

    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hello!
    I used to have an old website where my links were used like this:
    [domainname]/site/?id=about
    [domainname]/site/?id=contact

    instead of:
    [domainname]/site/about.php
    [domainname]/site/contact.php

    using the following code:
    PHP:
    <?php
        $code 
    $_GET['error'] or
        
    $code $_GET['guide'] or
        
    $code $_GET['id'] or
        
    $code $_GET['msg'] or
        
    $code $_GET['mybid'] or
        
    $code $_GET['x'];
        if (!empty(
    $code)) {
            
    $code .= '.php'
        if (!
    file_exists($code)) {
        include(
    $_SERVER['DOCUMENT_ROOT'] . "/site/404.php");
        }
        else {
        include(
    $code);
        }
        }
        else {
        include(
    $_SERVER['DOCUMENT_ROOT'] . "/site/scripts/html/index.html");
        }
    ?>
    So to explain, I had several $code's, which some of my pages were using ?id= while others were using ?guide=, etc.

    And when the link that was ?id=about or ?id=contact was not valid, it would send users to the 404 page, but if it existed, it would go to the direct page (ie. about.php).

    However, I also set it to where if someone accessed the folder directly ([domainname]/site), it would send to the index.html page which redirects to the mainpage.

    But since I am on a new server now and using the same script, it's causing me errors by stating:
    [01-Sep-2014 02:45:37 America/New_York] PHP Notice: Undefined index: error in /home/harux10m/public_html/site/scripts/php/getCode.php on line 2
    [01-Sep-2014 02:45:37 America/New_York] PHP Notice: Undefined index: guide in /home/harux10m/public_html/site/scripts/php/getCode.php on line 3
    [01-Sep-2014 02:45:37 America/New_York] PHP Notice: Undefined index: id in /home/harux10m/public_html/site/scripts/php/getCode.php on line 4
    [01-Sep-2014 02:45:37 America/New_York] PHP Notice: Undefined index: msg in /home/harux10m/public_html/site/scripts/php/getCode.php on line 5
    [01-Sep-2014 02:45:37 America/New_York] PHP Notice: Undefined index: mybid in /home/harux10m/public_html/site/scripts/php/getCode.php on line 6
    [01-Sep-2014 02:45:37 America/New_York] PHP Notice: Undefined index: x in /home/harux10m/public_html/site/scripts/php/getCode.php on line 7

    I googled and it says I need to do an isset function now, but is there a way to alter the coding I have above to match it up?

    Please let me know if you're confused or something.

    But thanks in advance if anyone can assist!

    PS [ The code works as usual, but I keep getting an error_log file generated. ]
     
    Last edited: Sep 1, 2014
  2. ttbx10ho

    ttbx10ho Member

    Messages:
    62
    Likes Received:
    5
    Trophy Points:
    8
    I write it a little different and use an array. Get no errors and every thing works. had to edit htaccess ErrorDocument 404 /?p=404
    Code:
    <?php
    $pages = array (
      index => array('name' => 'home' , 'title' => 'Hello World!' , 'page' => 'pages/home.php')
      about => array('name' => 'about' , 'title' => 'About' , 'page' => 'pages/about.php'),
      403 => array('name' => '403' , 'title' => '403 Forbidden' , 'page' => 'pages/403.php'),
      404 => array('name' => '404' , 'title' => '404 Not Found' , 'page' => 'pages/404.php')
       );
    
      if (isset ($_GET['p'])) {
        $pageID = $_GET['p'];
        if (! isset($pages[$pageID])) $pageID = 404;
      }
    else {
        $pageID = index;
      }
    define('this_page', $pages[$pageID]['name']);
    ?>
    This code in between the head title tags
    Code:
    <?php echo $pages[$pageID]['title']; ?>
    Then this code goes where ever you want your page to display.
    Code:
    <?php include $pages[$pageID]['page']; ?>
    I been wanting to improve it so that it looks in the /pages folder and if anything.php is there it will display if not 404.php. But its a work in progress. I'm working on it at http://ttb.x10host.com/ its slow but will have a zip file with a complete template.
     
    Last edited: Sep 1, 2014

Share This Page