Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Page Layout Help

    First: here is my script:
    PHP Code:
    <?php
    // Configuration (change these if you want)
    $filename "shouts.txt";    // The file to store shouts in
    $date "jS M, g:i A";        // Date format for shouts (see http://php.net/date)
    $timemod 0;            // Time modifier, in hours, use this to adjust the time
    $amount 0;            // Amount of shouts to show (0 = all)


    $shouthtml = <<<HTML
    {date}
    <br />
    {message}
    <p />
    HTML;

    $html = <<<HTML
    {shouts}
    <form method="post">
    {errors}
    <p />
    Message: <input type="text" name="message" />
    <p />
    <input type="submit" name="submit" value="Shout" />
    </form>
    <p />

    HTML;

    // Code

    if (!file_exists($filename))
    {
        
    // File does not exist, create it
        
    $f = @fopen($filename"w") or die("Cannot access $filename, wrong permissions maybe?");
        
    fclose($f);
    }

    if (isset(
    $_POST['submit']))
    {
        
    // User has clicked the "Shout" button
        
        // Make safe all posted data, also store other data
        
    if (get_magic_quotes_gpc())
        {
            
    $postmessage trim(stripslashes(htmlspecialchars($_POST['message'])));
        }
        else
        {
            
    $postmessage trim(htmlspecialchars($_POST['message']));
        }
        
    $postdate time();
        
        if (
    $postmessage == "")
        {
            
    $error .= "<span style=\"color: #FF0000;\">Please enter a message.</span> <br />";
        }
        
        if (isset(
    $error))
        {
            
    // An error has occurred
            // Format "error" part of HTML
            
    $html str_replace("{errors}"$error "<p />"$html);
        }
        else
        {
            
    // No errors :)
            // Add the shout
            
    $f fopen($filename"a");
            
    fwrite($f"[Date] $postdate\n[Msg] $postmessage\n");
            
    fclose($f);
            
    header("Location: " $_SERVER['PHP_SELF']);
            die();
        }
    }

    // Below: Handle all "shout" formatting

    $i 0;
    $f file($filename);
    foreach (
    $f as $val)
    {
        
    // Loop through every line in $filename
        
    if (preg_match("/\[Date\] [^A-Za-z ][0-9].*/"$val))
        {
            
    // Date line
            
    $shout[$i]['date'] = str_replace("[Date]"""$val);
        }
        if (
    preg_match("/\[Msg\] .*/"$val))
        {
            
    // Message line
            
    $shout[$i]['message'] = str_replace("[Msg]"""$val);
            
    $i++;
        }
    }

    // Have shouts going from the top-down
    $i 0;
    $shout = @array_reverse($shout);

    if (isset(
    $shout))
    {
        
    // If shouts exist
        
    foreach ($shout as $val => $key)
        {
            
    // Limit shouts according to $amount
            
    if ($i == $amount && $i != 0)
            {
            }
            else
            {
                
    // Create shout HTML
                
    $timeadd = (3600 $timemod);
                
    $moddate date($date$key['date'] + $timeadd); // Add time modifier to date

                
    $temphtml str_replace("{date}"$moddate$shouthtml);
                
    $temphtml str_replace("{message}"$key['message'], $temphtml);
                
    $allshouts .= $temphtml;
                
    $i++;
            }
        }
    }

    // Below: Handle all formatting

    // Format HTML to be outputted
    $html str_replace("{shouts}"$allshouts$html);
    $html str_replace("{errors}"""$html);
    echo 
    $html;

    ?>
    I need to change it so that the message entering form always stays at the top. Any idea how to do this? Thanks.

  • #2
    New Coder
    Join Date
    Jul 2007
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or, if possible make it so that after 50 shouts it creates a new page. (like facebook, or myspace)

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Why not just hard code the form into the html? As to the new page creation you are looking for pagination. There are many scripts available many of them for free on the net.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •