SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php theory and content system I'm working on.

    Hey guys/gals I have been a reader of this forum for a while now, I have read all the tutorials and I am still stuck I know there is a better way to do this but here is what I got so far. Keep in mind I'm pretty new to php. Anyhow here goes... Let's assume your trying to create a large site with a lot of content such as flash movies, stories ect..

    Create your main page layout and then insert this coding where you'd like your main content to go.

    <?
    if (file_exists("$page.html")) {
    include("$page.html");
    } else {
    // Page doesn't exist, so lets include the 404 error page or whatnot
    include("main.html");
    }
    ?>

    So that starts your site off. For any additional pages you just create the text to be entered on an html file for example "contactinfo.html" and then point the link towards it.

    Example http://www.yoursite.com/index.php?page=contactinfo

    ---------------------------------------------------------

    Now for the content part since most pages that host the movies/stories would be the same layout you could try this. You would first need to create the main template and leave room for fields like author, movie, size ect... now for this example call the page template.php.

    Now in this template you would layout everything the way you wanted it to look but then in the places you would want lets say the "author field" to show up you'd use $auth and then the file size you'd use $filesize ect...

    So you template file might look like this.

    This movie was submitted by $auth and is $filesize MB.

    ----------------------------------------------------------

    Now you need to have those fields filled in so you add this coding into the template file

    <?
    if (file_exists("$content.txt")) {
    include("$content.txt");
    } else {
    // Page doesn't exist, so lets include the 404 error page or whatnot
    include("404.html");
    }
    ?>

    and then create the link, to lets say http://www.yuoursite.com/template.php?content=1

    Now in the content 1.txt file all you would have are the required fields such as

    <? $auth ="John"; ?>
    <? $filesize =5; ?>

    ect.... So when every you wanted to update your site with new content you would just have to enter a few fields and then upload the file, create the link and your done.

    This is what I got done so far, I know I could make it alot better for example I think the "content.txt" files should be replaced with some sort of sql db so if you need to add more fields it would be easier. But I haven't found out how to do this yet with php. I know it's not too hard but I just haven't found out yet. I know there are a ton of professional php programmers that browse this board so if any of you would like to comment and possibly point me in the right direction that would be appreciated alot.

    A friend told me that by using a db I could also use php to make the main page of the site automated by it showing the last 5 entries to the db. So sections could be automated. I could also divide and display them into different categories?

    Anyone have some ideas to share on how I can make this little system better?

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Definitely run it off of a database...
    I would make sure there is a way for an administrator to control the files as a 'superuser'. Also, I would set some limitation to how large the file can be and where the file is placed. Other than that you have a great system started. Good luck

  3. #3
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In addition I'd suggest applying the basename() function to the filenames BEFORE you open the file. This will stop crackers from using your script to open any file on your web server (including those in password protected directories) by entering the full path to the page in the URL. Example:
    PHP Code:
    if (file_exists(basename("$page.html"))) { 
    include(
    basename("$page.html")); 


  4. #4
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So what do I need to do in php to get all the fields from the database and still have the pages created on the fly? I haven't been able to figure it out, even after much reading on the subject.

  5. #5
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if you want help in designing the SQL queries or what. But what you would be wanting to do would be this:

    Query the database and select your fields.
    Set them up as variables.
    And for a basic system just have <?=$variable?> in your template type page where you want those variables to go.

    At a later stage when you know a bit more it would be advisable to get rid of most if not all PHP code in that template page. So that it automatically scans the file and puts in the correct values.

    If you aren't familiar with classes, don't try this, but phplib could be what you are after for, if you want a prebuilt function of the above.

    To get it, go here:
    http://phplib.netuse.de/

    To get the jist of how the template class works, try these tutorials:
    http://www.devshed.com/Server_Side/P...Lib/print.html
    AND
    http://www.phpbuilder.com/columns/da...4&print_mode=1

    I recommend the phpbuilder.com one first, as I found it slightly easier to understand. After that move onto the devshed.com one, as the concepts in it are easier, even though they are the same, after reading the phpbuilder.com one.

    It might be a good idea to read up on classes at php.net first though:
    http://www.php.net/manual/en/language.oop.php

  6. #6
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm just looking for the php coding I need, I know how to use sql a bit I just don't know anything about php

  7. #7
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?

  8. #8
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is a lengthy example of how to use SQL and PHP together.

    PHP Code:
    <?php
    if($action == "browse"){
    // Set number to show per page
        
    if(!$results){
            
    $results 15;
        }
        
    // Set order type
        
    if(!$order){
            
    $order="update";
        }
        if(!
    $page){
            
    $start 0;
            
    $end $results;
        } else {
            
    $start "20 * ($page - 1)";
            
    $end $start $results;
        }
        
    $sql "SELECT id, username, date, update, email, display_email, title, description FROM $user_table WHERE display_public=1 ORDER BY $order LIMIT $start$end";
        
    $result mysql_query($sql);
        if(!
    $result){
            echo(
    "Database Error");
        } else {
            
    // create variable to determine number
            
    $i="1";
            while(
    $row mysql_fetch_array($result)){
                
    extract($row);
                
    // print out HTML
                
    ?>
                <table border="0" cellpadding="5" cellspacing="1">
                                <tr>
                                    <td><font face="verdana,arial" size="2"><?=$i?><?php if($display_email){
                                                                                    echo(
    '<a href=\"mailto:$email\">");
                                                                                    }
                                                                                ?><b>
                                                                                <?=$username?></b><?php if($display_email){
                                                                                echo("</a>");
                                                                                }?>- <a href="<?=$PHP_SELF?>?action=user&id=<?=$id?>"><?=$title?></a></font></td>
                                </tr>
                                <tr>
                                    <td align="right"><font face="verdana,arial" size="1">Created <?=$date?> | Modified <?=$update?></td>
                                </tr>
                                <tr>
                                    <td><blockquote><font face="verdana,arial" size="1"><?=change($description)?><br>
                                    </td>
                                </tr>
                </table>
                <?php
                // Return to WHILE Statement.
                $i++;
            } // End WHILE statement
            
            // Find Number of Total Results and display pages
            $total_results = mysql_num_rows(mysql_query(SELECT id FROM $user_table WHERE display_public=1));
            echo("Showing results $start - $end or $total_results<br>");
            echo("<a href="$PHP_SELF?order=$order&results=$results&browse=users&page=". $r-- ."\">Pervious Page >></a>");
            echo("<a href="$PHP_SELF?order=$order&results=$results&browse=users&page=". $r++ ."\">Next Page >></a> |");
            $r = "1";
            while($total_results > ($r * $results)){
                if($page != $r){
                    echo("<a href=\"$PHP_SELF?order=$order&results=$results&browse=users&page=$r\">$r</a> ");
                } else {
                    echo( $r );
                }
                $r++;
            }
                
        }
    }
    ?>
    Hope this helps, it's fairly long, but a good example I think. Hopefully it works, but no quarantees.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  9. #9
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a ton I will have to play around with that tonight.

    In your example is there a way to create a headlines type section were let's say the last 5 entires last made to the db get shown up as links?

    News Headlines:
    Link1
    Link2
    Link3 ect...

    Last Reviews:
    Movie1
    Movie2
    Movie3 ect...

    I have the db set up like this

    articles
    ----------
    id
    author
    date
    headline
    synopsis
    content
    categoryid
    title
    size
    homepage


    categories
    -------------
    id
    name
    //

  10. #10
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sure enough

    Not a problem: here is an example.

    PHP Code:
    <?php
    // top.php

    // Number of results
    $show 5;
    // Table Name
    $table table;
    if(isset(
    $category)){

        
    $sql "SELECT * FROM $table WHERE (date + 0) > (CURDATE() - 5) && (categoryid='$catagory') ORDER BY date DESC";
        
    $result mysql_query($sql);
        while(
    $row mysql_fetch_array($result)){
            
    extract($row);
            
    ?>
            document.write("<a href=\"display.php?articleid=<?=$id?>\"><?=$title?></a><br>");
            <?php
        
    }
    } else {
        echo(
    "No Category Selected");
    }
    Now you can use this anywhere on your site! Just use it as a JavaScript. You obviously don't have to, this concept can be used for anything, but it might be some insight into using PHP with other things.

    Code:
    <!-- example -->
    <html>
    <head>
    <title>My Newest Five</title>
    </head>
    <body bgcolor="white">
    My Top Five List
    <script src="/top.php?category=1"></script>
    </body>
    </html>
    God Bless
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  11. #11
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's what I was looking for thanks a ton


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
  •