Welcome to Geeklog, Anonymous Monday, December 05 2022 @ 07:33 pm EST

Geeklog Forums

PHP script format within static page


Status: offline

Rick78

Forum User
Regular Poster
Registered: 10/20/03
Posts: 98
Hello,

I have had this issue up before, but I never got a working solution.
I have a couple of PHP scripts that I would like to have run in a static page or in a block. I cannot seem to get it to work.
Can someone tell me what the format should be (what should be removed), since it is in a PHP environment ?
I have tried with all three settings for PHP in the static (execute, return, and do not execute). Which one should be used?
This is a simple script that takes forms and rewrites a template file, then sames the new file.

Thank you for any help.
Regards,
Rick
Here is the working code in a standalone php page on the same server:
Text Formatted Code

<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />
<HTML>
<HEAD>
<TITLE>1401 .CFG maker</TITLE>
</HEAD>

<body bgcolor="#FFFF99">
<script language="php">
  if ($submit)
  {
    //Change the value of below var to the location you want the file saved to
    //Remember to add the trailing / (slash)
    $outpath = "/mounted-storage/home71b/sub005/sc41175-ZRMB/galleries/playlists/grevepigerne/playlists3/";

    //This array keeps the list of "items" to change in the template file.
    $template_vars = array (
      "NAME"        => $NAME,
      "TITLE"       => $TITLE,
      "CREATOR"     => $CREATOR,
      "LOCATION"    => $LOCATION,
      "IMAGE"       => $IMAGE,
     );

    $fp = fopen("/mounted-storage/home71b/sub005/sc41175-ZRMB/grevepigerne.dk/geeklog/public_html/configurator/xml-template.xml", "rb");
    $template = fread($fp, filesize("/mounted-storage/home71b/sub005/sc41175-ZRMB/grevepigerne.dk/geeklog/public_html/configurator/xml-template.xml"));
    fclose($fp);

    $template = DoReplace($template, $template_vars);

    $outfile = $NAME.".xml";

    $fp = fopen($outpath.$outfile, "wb");
    fwrite($fp, $template);
    fclose($fp);

    print("File saved as: ".$outpath.$outfile."<BR>\n");
    print("<A HREF=\"".$PHP_SELF."\">Make another</A><BR><BR>");
    print("<CODE>".nl2br($template)."</CODE>\n");


  }
  else
  {
</script>

<h1 align="center">Configurator</h1>
<h3 align="center">Cisco 1401 (Interfaces: 1 ATM and 1 Ethernet )</h3>
<table align="center" border="0" width="82%">
  <tr>
    <td width="100%" align="center">
      <h6 align="left"><b><font size="2">The page will create a cfg file for
      the Cisco 1401 router to be used with a Teledanmark Pro Access connection
      with ATM termination. This configuration is designed for a 32
      bit&nbsp; outside (L0) netmask (255.255.255.255). The generated
      file will be placed on this server (10.2.115.44) in the default tftp
      directory.</font></b></h6>
    </td>
  </tr>
</table>


<FORM ACTION="<?php print($PHP_SELF) ?>?submit=yes" METHOD="POST">
<TABLE>
  <TR>
    <TD><b><font size="2">NAME: "Competition:"</font></b></TD>
    <TD><INPUT TYPE="TEXT" NAME="NAME"></TD>
  </TR>
 
  <TR>
    <TD><b><font size="2">Camera :</font></b></TD>
    <TD><INPUT TYPE="TEXT" NAME="TITLE"></TD>
  </TR>
  <TR>
    <TD><b><font size="2">Description :</font></b></TD>
    <TD><INPUT TYPE="TEXT" NAME="CREATOR"></TD>
  <TR>
  <TR>
    <TD><b><font size="2">Filename (no extention) :</font></b></TD>
    <TD><INPUT TYPE="TEXT" NAME="LOCATION"></TD>
  </TR>
  <TR>
    <TD><INPUT TYPE="SUBMIT" VALUE="Generate .CFG"></TD>
    <TD><INPUT TYPE="RESET" VALUE="Clear form"></TD>
  </TR>
</TABLE>
<?php
  }
?>
</BODY>
</HTML>

<?php
  function DoReplace($string, $array)
  {
    foreach ($array AS $key => $value)
    {
      $string = str_replace("{".$key."}", $value, $string);
    }
    return $string;
  }
?>
 
 Quote

Status: offline

1000ideen

Forum User
Full Member
Registered: 08/04/03
Posts: 1298

Status: offline

Rick78

Forum User
Regular Poster
Registered: 10/20/03
Posts: 98
Thank you for the reply.
I did not see that. everything was already enabled for PHP to work, in static pages.
I changed the tags to be reverse, just as the document descripes. The example works.
I am still the following error. Perhaps, the function is not correctly formated?

Error:
Parse error: syntax error, unexpected $end in /mounted-storage/home71b/sub005/sc41175-ZRMB/grevepigerne.dk/geeklog/plugins/staticpages/functions.inc(841) : eval()'d code on line 110

Thanks again for your help,
Rick



Text Formatted Code

?>
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<html>
<head>
<title>XML Playlist Maker</title>
</head>
<body bgcolor="#000000" text="#ffffff" vlink="#ffff00" alink="#0000ff" link="#993300">

<?php
  if ($submit)
  {
    //Change the value of below var to the location you want the file saved to
    //Remember to add the trailing / (slash)
    $outpath = "/mounted-storage/home71b/sub005/sc41175-ZRMB/galleries/playlists/grevepigerne/playlists/";

    //This array keeps the list of "items" to change in the template file.
    $template_vars = array (
      "NAME"        => $NAME,
      "TITLE"       => $TITLE,
      "CREATOR"     => $CREATOR,
      "LOCATION"    => $LOCATION,
    );

    $fp = fopen("/mounted-storage/home71b/sub005/sc41175-ZRMB/grevepigerne.dk/geeklog/public_html/configurator/xml-template-12.xml", "rb");
    $template = fread($fp, filesize("/mounted-storage/home71b/sub005/sc41175-ZRMB/grevepigerne.dk/geeklog/public_html/configurator/xml-template-12.xml"));
    fclose($fp);

    $template = DoReplace($template, $template_vars);

    $outfile = $NAME.".xml";

    $fp = fopen($outpath.$outfile, "wb");
    fwrite($fp, $template);
    fclose($fp);

    print("File saved as: ".$outpath.$outfile."<BR>\n");
    print("<A HREF=\"".$PHP_SELF."\">Make another</A><BR><BR>");
    print("<CODE>".nl2br($template)."</CODE>\n");
  }
  else
  {
?>
<h1 align="center">XML Playlist Creator 12</h1>
<h3 align="center"> </h3>
<table align="center" border="0" width="82%">
  <tr>
    <td width="100%" align="middle">
      <h6 align="left"><b><font size="2">      

       The page will create a XML
      page with 12 entrries in the list and save the file in
      galleries/playlists/grevepigerne/playlists.</font></b></h6>
    </td>
  </tr>
</table>


<form action="print($PHP_SELF) ?submit=yes" method="post">
<table>
  <tr height="69">
    <td><b><font size="2">Playlist Name: "Competition:"</font></b></td>
    <td><input name="NAME" style="WIDTH: 515px; HEIGHT: 22px" size="66"></td>
  </tr>
</table>
<br /><br /><br /><table>
  <tr height="30">
    <td><b><font size="2">Camera :</font></b></td>
    <td><input name="TITLE" value="Søren" style="WIDTH: 515px; HEIGHT: 22px" size="66"></td>
  </tr>
  <tr height="30">
    <td><b><font size="2">Description :</font></b></td>
    <td><input name="CREATOR" style="WIDTH: 515px; HEIGHT: 22px" size="66"></td>
  </tr>
  <tr height="30">
    <td><b><font size="2">Filename (no extention)
      :      
           </font></b></td>
    <td><input name="LOCATION" style="WIDTH: 515px; HEIGHT: 22px" size="66"></td>
  </tr>
</table>
<br /><br /><br /><table>
  <tr>
   <td><input type="submit" value="Generate .CFG"></td>
    <td><input type="reset" value="Clear form"></td>
  </tr>
</table>
</form>
</body>
</html>

<?php

  function DoReplace($string, $array)
  {
    foreach ($array AS $key => $value)
    {
      $string = str_replace("{".$key."}", $value, $string);
    }
    return $string;
  }
 
 Quote

Status: offline

Rick78

Forum User
Regular Poster
Registered: 10/20/03
Posts: 98
Hi Again,

I found that I had too many ' { '

I removed one, and now I get the form show. So that is great.
It is not writing the file though.
Is this line properly formated?
Text Formatted Code

 print("?><A HREF=\"".$PHP_SELF."\">Make another</A><BR><BR><?php");
 


Thanks,
Rick
 Quote

All times are EST. The time is now 07:33 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content