Jump to content


Photo

How do I add to a template then save the template as another name


  • Please log in to reply
3 replies to this topic

#1 HeyAwesomePeople

HeyAwesomePeople

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 20 June 2013 - 04:19 PM

Hello. I am trying to make it so that when a person enters there server info(For minecraft(game)) then it will take a template file, add in an edited peace of code, then save it called something else, somewhere else. Here is my PHP.

<?php
if($_POST['submit'])
{
    $name = htmlspecialchars($_POST['sName']);
    $ip   = htmlspecialchars($_POST['sIp']);
    $port = htmlspecialchars($_POST['sPort']);
    $desc = htmlspecialchars($_POST['sDesc']);
    $descName = "/home/content/85/9477285/html/uniqueminecraftservers/server/{$ip}.php";
    $finalName = "/home/content/85/9477285/html/uniqueminecraftservers/slist/{$ip}({$port}).php";
     
    if (file_exists($finalName))
    {
        echo 'File already exists';
    }
    else
    {
        $writestring = ' <tr>
        <td class="trank">*</td>
        <td class="tname"><p class="wrap-tname"><a href="server/'.$ip.'.php">'.$name.'</a></p></td>
        <td class="tserver">

<a href="server/'.$ip.'.php"><img style="border:none;width:468px;height:60px;" src="/uniqueminecraftservers/slist/banners/1.jpg"></a>

<br>IP: '.$ip.'</td>
        <td class="tport"><p class="wrap-ttype">'.$port.'</p></td>
        <td class="tplayers">2078/3000</td>
        <td class="tstatus Online">Online</td>
        </tr>';
        $file = fopen($finalName, "w");
        $size = filesize($finalName);
        fwrite($file, $writestring);
        fclose($file);
    }
    //Now start saving of description
        if (file_exists($descName))
    {
        echo 'File already exists';
    }
    else
    {
        $writestring = ' 
<span style="float: left; font-size: 34px;">Showing Server: '.$name.'</span><br /><br />

<table class="serverList">
            <tbody><tr>
                <th class="tname">Name</th>
                <th class="tdesc">Desc</th>
                <th class="ttype">Type</th>
                <th class="tplayers">Players</th>
                <th class="tstatus">Status</th>
            </tr>
<tr>
        <td class="tname"><p class="wrap-tname"><a href="server/'.$ip.'.php">'.$name.'</a></p></td>
        <td class="tserver">
'.$desc.'
</td>
        <td class="ttype"><p class="wrap-ttype">'.$type.'</p></td>
        <td class="tplayers">UNKNOWN</td>
        <td class="tstatus Online">UNKNOWN</td>
        </tr>
                    </tbody></table>

';
        $file = fopen($descName, "w");
        $size = filesize($descName);
        fwrite($file, $writestring);
        fclose($file);
        echo 'File Saved. Your server is now listed!';
    }
}
?>

Right now, this PHP code, when ran, first creates a server listing on the home page, then continues to $writestring to make another file. What I want to do is be able to take what is in that $writestring and replace $serverInfo with the $writestring in the template, then save the edited template somewhere else and keep the origanal template in its original form.

Hopefully you understood what I said.

Here is the template I want to use, and the keyword '.$serverInfo.' is where I want the contents of $writestring.

<!doctype html>
<title>Unique Minecraft Servers || Home</title>
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/uniqueminecraftservers/head/head.php";
include_once($path);
?>
<link rel="stylesheet" href="style.css">
</head>
<body id="body">

<div class="centered">
<div class="table1">
<img src="/uniqueminecraftservers/UMS.png" alt="UMS Banner" height="70" width="900">
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/uniqueminecraftservers/navmenu/navimenu.php";
include_once($path);
?></p>
</div>
</div>

'.$serverInfo.'

<div class="centered">
<div class="ad">
<p>Advertisment</p>
</div>
</div>

<div class="centered">
<div class="table1">
<p>

'.$server.'

</div>



<div class="centered">
<div class="ad">
<p>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-1405430741302930";
/* Bottom Ad 1 */
google_ad_slot = "2957143917";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</p>
</div>
</div>





</div>
</div>
</div>

</body>
</html>

I hope this all made sense. If not tell me and I will try to explain more.

Thanks!



#2 HeyAwesomePeople

HeyAwesomePeople

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 20 June 2013 - 04:32 PM

Basically I want it to create a new page USING the template, and that new page has this in a specific location:

<span style="float: left; font-size: 34px;">Showing Server: '.$name.'</span><br /><br />
 
<table class="serverList">
            <tbody><tr>
                <th class="tname">Name</th>
                <th class="tdesc">Desc</th>
                <th class="ttype">Type</th>
                <th class="tplayers">Players</th>
                <th class="tstatus">Status</th>
            </tr>
<tr>
        <td class="tname"><p class="wrap-tname"><a href="server/'.$ip.'.php">'.$name.'</a></p></td>
        <td class="tserver">
'.$desc.'
</td>
        <td class="ttype"><p class="wrap-ttype">'.$type.'</p></td>
        <td class="tplayers">UNKNOWN</td>
        <td class="tstatus Online">UNKNOWN</td>
        </tr>
                    </tbody></table>


#3 ginerjm

ginerjm

    Advanced Member

  • Members
  • PipPipPip
  • 1,772 posts
  • LocationVoorheesville NY

Posted 20 June 2013 - 05:00 PM

It amazes me that with your lack of understanding of English that you can program in any computer language.

JG

PS - If you're posting here you should be using:
        error_reporting(E_ALL | E_NOTICE);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!


#4 trq

trq

    Advanced Member

  • Administrators
  • 31,023 posts
  • LocationSydney, Australia.

Posted 20 June 2013 - 09:27 PM

It amazes me that with your lack of understanding of English that you can program in any computer language.

Not all user speak English natively. Your comment is not at all constructive.


http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com