SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    page navigation code could someone please advise as to whether this is a good way

    Hi,

    iam re-designing our large website. It will have a couple of different 'landing' areas and then more details pages within that section. I want the URL to read nicely and not jump around pages so i was trying to keep everything on one page and just use the variable to change the page contents.

    Does this seem like a sensible way to do it -

    Code:
    <? session_start(); ?>
    <?
    //use the variables in the URL string for the query
    if ($HTTP_SERVER_VARS['REDIRECT_PATH_INFO']) $HTTP_SERVER_VARS['PATH_INFO'] = $HTTP_SERVER_VARS['REDIRECT_PATH_INFO'];
    $data = explode("/",$HTTP_SERVER_VARS['PATH_INFO']);
    $_GET['section_one'] = $data[1];
    $_GET['section_two'] = $data[2];
    
    //clean up the strings and remove + signs if they are present
    $section_one_clean = ereg_replace("[ \t\r\n\+]+", " ", $_GET['section_one'] );
    $section_one = addslashes($section_one_clean);
    
    $section_two_clean = ereg_replace("[ \t\r\n\+]+", " ", $_GET['section_two'] );
    $section_two = addslashes($section_two_clean);
    
    $title_clean = ereg_replace("[ \t\r\n\+]+", " ", $_GET['title'] );
    $title = addslashes($title_clean);
    ?>
    <?php
    //check to see if any section has been selected if none go to default nav page
    if($section_one ==''){
    include('contents/what_we_do.php');
    }
    
    //if section_one does exist then use it to display the section landing page from the database
    elseif($section_one !=='' && $section_two=='') 
    {
    include('contents/landing_page.php');
    }
    
    //if section_one and section_two exists then display the contents pages.
    elseif($section_one !=='' && $section_two!==''){
    echo 'flipping ek it worked';
    }
    
    else {
    echo ' its all gone wrong somewhere';
    }
    
    ?>
    your thoughts/suggestions appreciated. thanks
    If i am a product of your imagination you should try harder!

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,069
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Noppy View Post
    Hi,

    iam re-designing our large website. It will have a couple of different 'landing' areas and then more details pages within that section. I want the URL to read nicely and not jump around pages so i was trying to keep everything on one page and just use the variable to change the page contents.

    Does this seem like a sensible way to do it -

    Code:
    <? session_start(); ?>
    <?
    //use the variables in the URL string for the query
    if ($HTTP_SERVER_VARS['REDIRECT_PATH_INFO']) $HTTP_SERVER_VARS['PATH_INFO'] = $HTTP_SERVER_VARS['REDIRECT_PATH_INFO'];
    $data = explode("/",$HTTP_SERVER_VARS['PATH_INFO']);
    $_GET['section_one'] = $data[1];
    $_GET['section_two'] = $data[2];
    
    //clean up the strings and remove + signs if they are present
    $section_one_clean = ereg_replace("[ \t\r\n\+]+", " ", $_GET['section_one'] );
    $section_one = addslashes($section_one_clean);
    
    $section_two_clean = ereg_replace("[ \t\r\n\+]+", " ", $_GET['section_two'] );
    $section_two = addslashes($section_two_clean);
    
    $title_clean = ereg_replace("[ \t\r\n\+]+", " ", $_GET['title'] );
    $title = addslashes($title_clean);
    ?>
    <?php
    //check to see if any section has been selected if none go to default nav page
    if($section_one ==''){
    include('contents/what_we_do.php');
    }
    
    //if section_one does exist then use it to display the section landing page from the database
    elseif($section_one !=='' && $section_two=='') 
    {
    include('contents/landing_page.php');
    }
    
    //if section_one and section_two exists then display the contents pages.
    elseif($section_one !=='' && $section_two!==''){
    echo 'flipping ek it worked';
    }
    
    else {
    echo ' its all gone wrong somewhere';
    }
    
    ?>
    your thoughts/suggestions appreciated. thanks
    Well, I have a lot of thoughts about your post.

    1st. Use Apache RewriteRules or Isapi Rewrite for IIS to create and use nice url's
    2nd. Ereg_replace will be gone in PHP6, if your redesigning the whole website, please don't use it (use preg_replace() instead, that stays in 6).
    3th. Same goes for $HTTP_SERVER_VARS (use $_SERVER)
    4th. Use functions to make your code more readable. You use the exact same processing on the $section_one, $section_two and title variables. If you were to create a function like

    PHP Code:
    function clean(str) {
      return 
    addslashes(preg_replace("/[ \t\r\n\+]+/"$str));

    You could than use
    PHP Code:
    $section_one clean($_GET['section1']);
    $section_two clean($_GET['section2']);
    $title clean($_GET['title']); 
    Or even
    PHP Code:
    list($section_one,$section_two,$title) = array_map('clean', array($_GET['section_one'], $_GET['section_two'], $_GET['title'])); 
    If that's more your cup of tea
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    many thanks,
    thats certainly good to know that its no longer being used in php6 iam sure to impliment that now to save problems in the future.

    Thanks for the code, i'll see how i get on.
    If i am a product of your imagination you should try harder!

  4. #4
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    i tried your code and it didnt work initially as it gave an error saying not enough parameters. So i had a bit of a read and realised that it needed the second parameter of what to replace with (just added " " to give a space) and it works now as so -

    Code:
    function clean($str){
      return addslashes(preg_replace("/[ \t\r\n\+]+/"," ", $str));
    }
    many thanks
    its a lot neater now
    If i am a product of your imagination you should try harder!


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
  •