Jump to content

Create New PHP File


cjbeck71081

Recommended Posts

I am implementing a content management system that is customized.  I would like the ability to add new pages to the CMS and I was wondering what the best practice was for creating new PHP documents and editing them.

 

Secondly i was wondering how search engine friendly a completely CMS based site is with all of the <?include ?> codes in the actual code... do the search engines read that well?

Link to comment
Share on other sites

cjbeck71081,

 

  It's a matter of escaping those chars that will be present on the newly created php file.

 

  The following example is a sub-set from a working script...

 

  I couldn't wrap it in [ code ] /  [ /code ] elements because this parser complained about the opening single-quotes before the closing $PHPCode[] = '?>' . " \n"; statements..

 

Hope this helps.

 

Scot L. Diddle, Richmond VA

 

<?php

 

/**

*

*  Define where to place our newly defined HZForm.php file...

*

* This is the form the user fill out, then submits for Smarty processing, and

*  subsequent email processing.

*

*/

 

$HZForm_dir = $_SERVER['DOCUMENT_ROOT'];

 

// Which form is the user dealing with ?

$HZForm_FileName  = 'HZForm.php';

 

$HZFormFile =  $HZForm_dir . '/' . $HZForm_FileName;

 

if (file_exists($HZFormFile)) { // Get rid of any previous HZForm.php File... It may be out of date.

 

$deleteResults = unlink($HZFormFile);

 

if (!$deleteResults) {

 

$error  =  " ERROR: Could not delete previous version of HZForm.php file.<br /><br>";

$error .=  "        Please report this error to the IS Helpdesk.  Ask for WebForms help for form: \"HAZSPILL\"<br /><br>";

echo $error;

exit;

 

}

 

}

 

/**

*

*  Tack on those items that Smarty processing complains about

*

*/

 

$debug1 = FALSE; // Display $_SESSION['POST'] vars...

$debug2 = TRUE;  // Revert to in-line JS for debugging.

 

$PHPCode = array();

 

$PHPCode[]  = '<?php' . "\n";

$PHPCode[]  = "\n";

$PHPCode[]  = "\n\t\$currentProgram = \$_SERVER['PHP_SELF']; \n";

$PHPCode[]  = "\n";

$PHPCode[]  = "\n\t\$currentProgramPieces = explode('/', \$currentProgram); \n";

$PHPCode[]  = "\n";

$PHPCode[]  = "\n\t\$_PHPSELF = \$currentProgramPieces[1]; \n";

$PHPCode[]  = "\n";

 

$PHPCode[]  = "\tif (!empty(\$_POST)) {" . "\n";

 

$PHPCode[]  = "\t\t\$_SESSION['POST'] = array(); \n";

 

$PHPCode[]  = "\t\tforeach(\$_POST as \$IDX=> \$DBCandidate) {  \n";

$PHPCode[]  = "\t\t\t\$_SESSION['POST'][\$IDX] = \$DBCandidate;  \n";

$PHPCode[]  = "\t\t}" . "\n";

 

if ($debug1) { // Just above...

 

$PHPCode[] = "\t\t require_once('include/debugFunctions.php');" . "\n";

$PHPCode[] = "\t\t printArray(\$_POST, '\$_POST');" . "\n";

 

$PHPCode[] = "\t\t printArray(\$_SESSION['POST'], 'POST');" . "\n";

$PHPCode[] = "\n";

$PHPCode[] = "\t\t exit();" . "\n";

 

}

 

$PHPCode[] = "\n";

 

$PHPCode[] = "\t\trequire('include/loadHZDB.php'); \n ";

 

$PHPCode[] = "\n";

 

$PHPCode[] = "\t // exit();  \n";

 

 

$PHPCode[] = "\theader('Location: HZSmartyCall.php'); \n ";

$PHPCode[] = "\texit();  \n";

$PHPCode[] = "\n";

$PHPCode[]  = "\t}" . "\n";

 

$PHPCode[] = '?>' .  " \n";

 

$headItems  = array();

 

 

if ($debug2) { // Just above...

 

$PHPCode[]  = '<?php' . "\n";

 

$PHPCode[]  = "\techo \"<script type='text/javascript'> \n\"; \n";

 

$PHPCode[] = "\n";

$PHPCode[] = "\trequire('javascript/HZScripts.js'); \n" . "\n";

$PHPCode[] = "\n";

 

$PHPCode[]  = "\techo \"</script> \n\"; " . "\n";

 

$PHPCode[] = '?>' .  " \n";

 

}

else {

$headItems[] = "\t <script type=\"text/javascript\" language=\"JavaScript\" src=\"javascript/HZScripts.js\"></script> \n";

}

 

$headItems[] = "\t<link href=\"css/WebForms.css\" rel=\"stylesheet\" type=\"text/css\" ></link> \n";

 

$currentFormLines = $_SESSION['hzOut'];

 

$hzLine = array();

 

$lineOut = 0;

$next    = FALSE;

 

foreach($PHPCode as $PHPCodeIn) {

 

$hzLine[$lineOut] = $PHPCodeIn;

$lineOut++;

 

}

 

foreach($currentFormLines as $hzLineIn) {

 

$stristrResult = stristr($hzLineIn, '<title>');

 

if ($next) {

 

$next = FALSE;

 

foreach($headItems as $headItemsIn) {

 

$hzLine[$lineOut] = $headItemsIn;

$lineOut++;

 

}

 

}

else {

 

if ($stristrResult) {

$next = 'TRUE';

}

 

$hzLine[$lineOut] = $hzLineIn;

 

$lineOut++;

 

}

 

}

 

      $lines = count($hzLine);

     

      $fh = fopen($HZFormFile, 'w');

     

      if (!$fh) {

     

      echo "ERROR: Could not write the HAZSPILL User Form... Please report this error to the HelpDesk.";

      exit;

     

      }

 

      for ($i=0; $i < $lines; $i++) {

 

      $stristrQuery = stristr($hzLine[$i], '<textarea');

     

      if (!$stristrQuery) {

      $hzLine[$i] .= "\n";

      }

     

$success = fwrite($fh, $hzLine[$i]);

 

if (!$success) {

$errorOccured = TRUE;

}

 

      }

 

 

if (!$errorOccured) {

 

// Now that we have written out the form, show it to the user.

header('Location: ' . $HZForm_FileName );

exit;

 

}

else {

 

$error  =  " ERROR: Could not write new version of  \$_SESSION['hzOut'].php file.<br /><br>";

$error .=  "        Please report this error to the IS Helpdesk.  Ask for WebForms help for form: \"HAZSPILL\"<br /><br>";

echo $error;

 

exit;

 

}

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.