Jump to content

Recommended Posts

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!

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