Inherited php site that ran on an old server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mk1200
Forum Newbie
Posts: 2
Joined: Sun Aug 30, 2009 7:41 pm

Inherited php site that ran on an old server

Post by mk1200 »

My server is running php 5.2.6 and some modules of the site won't work.

I paid a freelancer to take a look when the site was first moved. He said the code is old and will need to be upgraded. Registered_Globals has to be on. He fixed a few major parts, but there are a few minor issues that I just found. The entire site was written by someone who is no longer available.

So break me in easy, what would have to change in these 2 files to make this simple announcement module to work properly? Hopefully there is some format to follow, so I can apply to the other broken files.

Right now these 2 files don't update the db. Everything looks and acts functional, but the data stays the same.

Code: Select all

<?
 
if($action == 1) {
    $file_open = fopen('../scroller_array.php', 'w+') ;
    $file_text = '<?' ;
    foreach($_POST[announcement] as $key => $value) {
        $file_text .= '$message['.$key.'] = "'.$value . '";' ;
    }
    $file_text .= '?>' ;
    $file_write = fwrite($file_open, $file_text) ;
    $file_close = fclose($file_open) ;
}
 
include('header.php') ;
 
echo '<h1>Manage Announcements</h1>' ;
 
include('../scroller_array.php') ;
 
echo '<form action="announcements.php" method="post">' ;
echo '<input type="hidden" name="action" value="1" />' ;
 
$ctrl = 0 ;
while($ctrl < 10) {
    echo '<textarea name="announcement[]" style="width: 700px ; margin-bottom: 3px" rows="3">' . $message[$ctrl] . '</textarea><br />' ;
    ++$ctrl ;
}
 
echo '<input type="submit" value="Update &raquo;" />' ;
echo '</form>' ;
 
include('footer.php') ;
 
?>

Code: Select all

<?
 
$announcement1 = str_replace("\'", "&rsquo;", $announcement1) ;
$announcement1 = str_replace('\"', '"', $announcement1) ;
$announcement2 = str_replace("\'", "&rsquo;", $announcement2) ;
$announcement2 = str_replace('\"', '"', $announcement2) ;
$announcement3 = str_replace("\'", "&rsquo;", $announcement3) ;
$announcement3 = str_replace('\"', '"', $announcement3) ;
 
$file1 = fopen('../announcement1.txt', 'w+') ;
$write1 = fwrite($file1, $announcement1) ;
$close1 = fclose($file1) ;
 
$file2 = fopen('../announcement2.txt', 'w+') ;
$write2 = fwrite($file2, $announcement2) ;
$close2 = fclose($file2) ;
 
$file3 = fopen('../announcement3.txt', 'w+') ;
$write3 = fwrite($file3, $announcement3) ;
$close3 = fclose($file3) ;
 
include('header.php') ;
 
?>
<h1>
    Success!</h1>
<p style="text-align: center">
    Announcments updated!</p>
<? include('footer.php') ?>
AlanG
Forum Contributor
Posts: 136
Joined: Wed Jun 10, 2009 1:03 am

Re: Inherited php site that ran on an old server

Post by AlanG »

Is registered globals on? I'd suggest you leave them turned off and adjust the code. As for a database, there is no database code in your code blocks so I assume your referring to the file. Also, you should turn off short tags and change all the <? to <?php (Just incase your using XML).

Code: Select all

<?php
// The $action variable was relying on register globals to be set, this will set it regardless of the register globals setting
$action = (isset($_POST['action']) && !empty($_POST['action'])) ? $_POST['action'] : 0;
 
if($action == 1) {
    $file_open = fopen('../scroller_array.php', 'w+') ;
    $file_text = '<?' ;
    foreach($_POST[announcement] as $key => $value) {
        $file_text .= '$message['.$key.'] = "'.$value . '";' ;
    }
    $file_text .= '?>' ;
    $file_write = fwrite($file_open, $file_text) ;
    $file_close = fclose($file_open) ;
}
 
include('header.php') ;
 
echo '<h1>Manage Announcements</h1>' ;
 
include('../scroller_array.php') ;
 
echo '<form action="announcements.php" method="post">' ;
echo '<input type="hidden" name="action" value="1" />' ;
 
$ctrl = 0 ;
while($ctrl < 10) {
    echo '<textarea name="announcement[]" style="width: 700px ; margin-bottom: 3px" rows="3">' . $message[$ctrl] . '</textarea><br />' ;
    ++$ctrl ;
}
 
echo '<input type="submit" value="Update &raquo;" />' ;
echo '</form>' ;
 
include('footer.php') ;
?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Inherited php site that ran on an old server

Post by Benjamin »

AlanG wrote:Is registered globals on? I'd suggest you leave them turned off and adjust the code. As for a database, there is no database code in your code blocks so I assume your referring to the file. Also, you should turn off short tags and change all the <? to <?php (Just incase your using XML).

Code: Select all

<?php
// The $action variable was relying on register globals to be set, this will set it regardless of the register globals setting
$action = (isset($_POST['action']) && !empty($_POST['action'])) ? $_POST['action'] : 0;
 
if($action == 1) {
    $file_open = fopen('../scroller_array.php', 'w+') ;
    $file_text = '<?' ;
    foreach($_POST[announcement] as $key => $value) {
        $file_text .= '$message['.$key.'] = "'.$value . '";' ;
    }
    $file_text .= '?>' ;
    $file_write = fwrite($file_open, $file_text) ;
    $file_close = fclose($file_open) ;
}
 
include('header.php') ;
 
echo '<h1>Manage Announcements</h1>' ;
 
include('../scroller_array.php') ;
 
echo '<form action="announcements.php" method="post">' ;
echo '<input type="hidden" name="action" value="1" />' ;
 
$ctrl = 0 ;
while($ctrl < 10) {
    echo '<textarea name="announcement[]" style="width: 700px ; margin-bottom: 3px" rows="3">' . $message[$ctrl] . '</textarea><br />' ;
    ++$ctrl ;
}
 
echo '<input type="submit" value="Update &raquo;" />' ;
echo '</form>' ;
 
include('footer.php') ;
?>
Don't forget the short tag on line 7. You can also enable short tags in php.ini, which would save you the hassle of digging through all the code.
mk1200
Forum Newbie
Posts: 2
Joined: Sun Aug 30, 2009 7:41 pm

Re: Inherited php site that ran on an old server

Post by mk1200 »

Yeah, registered_globals has to be on for the time being. Too much is relying on it. Thanks for the edits guys, I'll give it a shot this morning.
Post Reply