Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 11 of 11

This is a discussion on Browse by topic ID in the Shared & Semi-Dedicated forum
I'm sure this is fairly easy to do with PHP, but I can't seem to find any information on how it might be done, so ...

  1. #1
    JPC Guru
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    389

    Browse by topic ID

    I'm sure this is fairly easy to do with PHP, but I can't seem to find any information on how it might be done, so I hope you can help.

    I'm wanted to design a simple navigation page where forum topics can be browsed by their topic ID. Or, for that matter, where any numbered files can be browsed.

    Alright, that was confusing, lemme explain it this way.

    Say I have some articles set up as 0001.html, 0002.html, 0003.html ... 5364.html, etc. I'd want to have a way to browse through these files by their numbered names. Like, if I'm looking at 0031.html and click next it would take me to 0032.html.

    I'm asking because a friend wants to implement this on his site without having to manually edit the code for thousands of pages in order to have Next and Previous links. If there's any way to implement this, I"m sure it's with PHP.

    So, is there any way to specify a starting point (which numbered file to start at) and have PHP "know" to just look for 1 number higher to use as the "next" hyperlink and 1 number lower to use as the "Previous" hyperlink?

    This is beyond me, but I figured I'd at least ask here.

  2. #2
    Ron
    Guest
    yeah, you could have a little php program that would look at the REQUEST_URI and display the file, and build the link... I'll see fi I have an example on hand.

  3. #3
    Ron
    Guest
    Code:
    $term=substr($_SERVER['REQUEST_URI'],0, strpos($_SERVER['REQUEST_URI'],".shtml"));
    $term=substr($term,strrpos($term,"/")+1);
    This will get you the file number ASSUMING that the request is in the format of www.domain.com/<somedir>/#####.shtml

    Then print out the requested file here....

    Then something like:
    Code:
    printf ("<CENTER><A HREF=\"http://www.domain.com/<somedir>/%d.shtml\" >NEXT FILE</A><br></CENTER>", $term+1);
    printf ("<CENTER><A HREF=\"http://www.domain.com/<somedir>/%d.shtml\" >PREVIOUS FILE</A></CENTER>", $term-1);
    The way I have it work is that I directed inquiries to a non-existant directory, and any requests for that subdirectory are redirected with .htaccess to the php program.

    In actuality I have mod_rewrite take the filename and parse it out, and send it to a .shtml page with
    "program.shtml?term=####" so that the term is already available.

    That .shtml page has an SSI that invokes the program. I did all that so I could maintain the .shtml page with NetObject Fusion to maintain site look&feel around the output. The other approach was an older less sophisticated version which might be better for you.

    I'm sure there are a million other ways to do this, some more reasonable for what you're trying to do.
    EDIT:
    You know what, I should give a more accurate response than this... this is gonna require you to fiddle around with it to gert it working. If you want a working solution, let me know, and I'll outline the steps I use to do it all.

  4. #4
    JPC Guru
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    389
    Yeah... You had me there up until the part where .htaccess is needed. Then my eyes glazed over, lol.

    Sounds like it'll work though. Can I also use that for html rather than shtml or is there a specific reason shtml is needed?

    Thanks, Ron!

  5. #5
    Ron
    Guest
    Ok, here's a working solution... it may be overkill for you, or not, but here it is, working on my site:

    www.oes.org/galenFake/1.html <disabled>

    You can also use the programfile directly by:
    www.oes.org/galenReal/galen.php?term=1<disabled>


    Here's how it works:
    in my docroot (www) directory, in .htaccess , I have the lines:
    Code:
    RewriteEngine On
    RewriteRule ^galenFake/(.*)\.html$ /galenReal/galen.shtml
    In www.oes.org/galenReal <disabled> I have the following files:
    galen.shtml,
    galen.php, and
    text files 1.html, 2.html, 3.html, 4.html

    You can look at the directory yourself.
    www.oes.org/galenReal <disabled>

    galen.shtml has the following line:
    Code:
    <!--#include virtual="galen.php" -->
    This line is why the .shtml file ending is required for this file only. it tells Apache to process that #include Virtual line as a Server Side Include.


    galen.php has the following:
    Code:
    <?php
    /************************************************
     *                                 Galen.php
     *                             -------------------
     *               This displays a file and creates links to the next one.
     *
     *
     *               Written by Ron, 5/21/2004
     ************************************************/
    
    $target=$_GET['term']; // get the term from the passed variable.
    if (! $target) // If there's no term set, find the "filename" term and get it.
    {
       $term=substr($_SERVER['REQUEST_URI'],0, strpos($_SERVER['REQUEST_URI'],".html"));
       $target=substr($term,strrpos($term,"/")+1);
    }
    
    $unixFileName=$target . ".html";
    
    printf ("<CENTER><A HREF=\"http://www.oes.org/galenFake/%d.html\" >NEXT FILE</A><br></CENTER>", $target+1);
    printf ("<CENTER><A HREF=\"http://www.oes.org/galenFake/%d.html\" >PREVIOUS FILE</A></CENTER>", $target-1);
    
    printf("%s<br>", file_get_contents($unixFileName));
    
    printf ("<CENTER><A HREF=\"http://www.oes.org/galenFake/%d.html\" >NEXT FILE</A><br></CENTER>", $target+1);
    printf ("<CENTER><A HREF=\"http://www.oes.org/galenFake/%d.html\" >PREVIOUS FILE</A></CENTER>", $target-1);
    ?>
    This does EXACTLY what you asked for, and little else. This is for illistrative purposes only -- I would never use code like this -- it has no error checking. For instance, I'd check for the existance of the files.

    Also, this probaqbly won't work with files named 0001 0002 and so forth, you'll have to do a little string maipulation inside of galen.php to get that accomplished.

    There are probably programs out there that will allow people to see filenames contained within directories that would be quite simple to implement.

    Have fun!

    PS A couple of notes:
    1) galenFake dierctory does NOT exist!
    2) added benefit: hides true location of files

    EDIT:
    Changed the method for getting the file and printing it to something that is better security-wise.

  6. #6
    JPC Guru
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    389
    Hmm... It does indeed work and I'll keep this in mind if I should ever need to do this in the future, but this would still require my friend to edit thousands of files to include the SSI script.

    Since this is the way it would need to be done, then I suppose that means there isn't a way to apply this to an existing system. Ah well, I didn't expect to find a way anyhow.

    This was still cool to learn though, so thanks a lot Ron! I've copied your post and saved it for future reference

  7. #7
    Ron
    Guest
    No, it only requires those 2 files, Galen.

    The galenReal directory is your friend's directory that contains the all the .html files, as well as the galen.php and galen.shtml files.

    The galenFake directory doesn't exist, and is referenced by the .htaccess file.

    all you need is a refernce somewhere to one of the files, in the "Fake" directory.

    Don't you see this is exactly how this worked-- this thread referenced galenFake/1.html and then all of the other files were visible in links??

  8. #8
    Ron
    Guest
    Really, I kid you not.....

  9. #9
    JPC Guru
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    389
    OHHHHH! Cool! Thanks Ron, I'm gonna play around with this a bit to learn it better, but I'm sure it'll work. That's awesome! Thanks a lot!

  10. #10
    Ron
    Guest
    Galen .... let me know when I can take down this stuff from my site, ok? I'll leave it up as long as you need.

    Thx

  11. #11
    JPC Guru
    Join Date
    Jan 2004
    Location
    I'm right behind you....
    Posts
    389
    Sorry, I didn't see that you posted again. I have all the stuff now, you can take it down. Thanks again!

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
  •