Jump to content

PHP4 to PHP5


hud1n1

Recommended Posts

Hi...

 

I could really do with some help, I have some form code I have been using for a very long time.

how every my server company will not install php4 anymore  :(

 

Can someone have a look at this code and let me know why its not php5 compatible.

 

Thanks

 



<?php



/* $sendto is the email where form results are sent to */
   $sendto = "........";

/* $ccto is the email where form results can be carbon copied to */
   $ccto = "...........";

/*
         O P T I O N A L   V A R I A B L E S 
*/


/*
TO POST PHP ERRORS TO PAGE FOR DEBUGING SET:
$report_errors = "ALL";


TO REMOVE PHP ERRORS FROM POSTING TO THE PAGE FOR USE SET:
$report_errors = "NONE";

*/
$report_errors = "NONE";


$setokurl = "1";

$okurls = "http://www.dwcontractors.com";



if ($report_errors == "NONE") {
error_reporting(0);
}else{
error_reporting(E_ALL);
}


/* --- I F   S E T   O K   U R L   = 1  ----- */

if ($setokurl == "1"){

  $found_url = "0";
  $referer =$_SERVER["HTTP_REFERER"];
  $referer = str_replace("://", "[CS]", $referer);
  $referer_sp = explode("/", $referer);
  $referer = "$referer_sp[0]";
  $referer .= "/";
  $referer = str_replace("[CS]", "://", $referer);
  $referer = strtolower($referer);

  $okurls = split(",", $okurls);

foreach ($okurls as $myokurls) {

$myokurls = strtolower($myokurls);

     if ($referer == strtolower($myokurls)) { 
      $found_url = "1"; 
      }

  }

  if ($found_url == "0") {
  $ERROR_action = "bad_okurl";
  include("$PATH_error$PAGE_error");
  }

}
/* --- E N D   I F   S E T   O K   U R L   = 1  --- */



/* check to see if posted */
if ($HTTP_GET_VARS || ! $HTTP_POST_VARS || $_GET || ! $_POST) {
include("nverror.php4");
no_pst();

}else{


/* IF OLDER VERSION OF PHP CONVERT TO NEWER VARIABLES */
if (! $_POST) {
$_POST = "$HTTP_POST_VARS";
}

if (! $_SERVER) {
$_SERVER = "$HTTP_SERVER_VARS";
}


$year = date("Y");
$month = date("m");
$day = date("d");
$hour = date("h");
$min = date("i");
$tod = date("a");


$ip=$_SERVER["REMOTE_ADDR"];

$SEND_prnt = "The form below was submited by " . $_POST{"email"} . " from Ip address: $ip on $monthnameactual $month/$day/$year at $hour:$min $tod \n";
$SEND_prnt .= "--- DW Contractors ---\n\n";


/* CHECK TO SEE IF $_POST{"required"} IS SET */
if ($_POST{"required"}){


  $post_required = $_POST{"required"};
  $required = split(",", $post_required);
  $reqnum = count($required);

for ($req=0; $req < $reqnum; $req++) {

$REQ_name = $required[$req];
$REQ_value = $POST{"$REQ_name"};


  if ($REQ_name == "email") {
     $goodem = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $_POST{"email"}, $trashed);

        if (! $goodem) {
include("nverror.php4");
msng_email();
        }  /* end ! $goodem */

  }
  elseif (! $_POST{"$REQ_name"}) {
		 $isreqe = "1";
		 $REQ_error .= "<li> $REQ_name ";
  		 } /* end ! req val */

          } /* end REQ for loop  */


                /* IF THERE ARE ANY REQUIRED FIELDS NOT FILLED IN */

	if ($isreqe == "1") {
	include("nverror.php4");
	msng_required();
	}


} /* END CHECK TO SEE IF $_POST{"required"} IS SET */


/* END IF THERE ARE ANY REQUIRED FIELDS NOT FILLED IN */


/* GET POSTED VARIABLES */


foreach ($_POST as $NVPOST_name => $NVPOST_value) {

$NVPOST_value = str_replace("\n", "", $NVPOST_value);
$NVPOST_value = str_replace("\r", "", $NVPOST_value);

$NVPOST_value = preg_replace("'\cc:'si", "Cc ", $NVPOST_value);
$NVPOST_value = preg_replace("'\bcc:'si", "bcc ", $NVPOST_value);
$NVPOST_value = preg_replace("'\to:'si", "to ", $NVPOST_value);
$NVPOST_value = preg_replace("'\bc:'si", "bc ", $NVPOST_value);



if (strtolower($NVPOST_name) == "subject") {

$NVPOST_value = str_replace(":", ";", $NVPOST_value);
}


            /* G E T   E M A I L */
       
            if (strtolower($NVPOST_name) == "email") {
            $SEND_email = "$NVPOST_value";
    $SEND_email = str_replace(":", "", $SEND_email);
    $SEND_email = str_replace(" ", "", $SEND_email);
            }

            /* END GET LEADS EMAIL */

   if (! $_POST{"sort"}) {


                            /* CHECK TO SEE IF CONFIG FIELD */
                            if ($NVPOST_name == "subject" || $NVPOST_name == "sort" || $NVPOST_name == "required" || $NVPOST_name == "success_page"){}else{
                            $SEND_prnt .= "$NVPOST_name:  $NVPOST_value \n\n";
                            }
   } /* end ! sort */
  

} /* end foreach */


  /* END GET POSTED VARIABLES */




  if ($_POST{"sort"}) {

  /* SORT VARIABLES */

$sortvars = split(",", $_POST{"sort"});
$sortnum = count($sortvars);

               for ($num=0; $num < $sortnum; $num++) {
       $SEND_prnt .= "$sortvars[$num]: " . $_POST{"$sortvars[$num]"} . " \n\n";
       }

  }   /* END SORT VARIABLES */




/* send mail */


if (! $ccto) {
$header = "From: $SEND_email\r\nReply-to: $SEND_email";
}else{
$header = "From: $SEND_email\r\nReply-to: $SEND_email\r\nCc: $ccto";
}


mail($sendto, $_POST{"subject"}, $SEND_prnt, $header);

/* END sendmail */

     /* CHECK TO SEE IF FORM SPECIFYS A SUCCESS PAGE */
     if (! $_POST{"success_page"}) {

include("nverror.php4");
default_success();

     }else{
     $successpage=$_POST{"success_page"};
     header("Location: $successpage");  /* redirect */  
     exit;
     }



} /* END IF POSTED */


?>

 

Link to comment
https://forums.phpfreaks.com/topic/228372-php4-to-php5/
Share on other sites

Thanks to both of you for your replies ...

I know it works on php4 because when i was able to choose the php version it worked fine but now its php5 or nothing.

 

The error message I get when the server is running in php5 is:

Error 405 Method Not Allowed

 

The only reason i'm still using this form code is because it the only one i have every found were you don't have to specify all the field and the outgoing email info. 

Link to comment
https://forums.phpfreaks.com/topic/228372-php4-to-php5/#findComment-1177632
Share on other sites

You didn't state exactly at what point you get the 405 Method Not Allowed error, but if it is at the point where you submit your form, it is likely that the action="..." attribute of your form is invalid and if it is being produced by php code, then that php code would be where the problem is at.

Link to comment
https://forums.phpfreaks.com/topic/228372-php4-to-php5/#findComment-1177651
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.