[HTML or PHP] Include a File, Edit, and Save?

Edit: I spoke too soon...

It opens a text box with this:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$title</title>
<meta http-equiv="keywords" content="$keyword" />
<meta http-equiv="description" content="$description" />
<meta http-equiv="Content-Type" content="text/html; charset=$encoding" />
</head>
<body>

<script src="languages/$language.js" type="text/javascript"></script>
<script src="javascript/aliboard.js" type="text/javascript"></script>
<script type="text/javascript">
	<!-- JAVASCRIPT_CODES -->
</script>

<link href="themes/default/stylesheet/main-style.css" rel="stylesheet" type="text/css" />

<div style="width:auto;" align="center">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
	<tr>
		<td>
	
	
	<center>
	<div class="header"></div>
	<div class="navigation_border">
<div id="mytabsmenu" class="tabsmenuclass">
<ul>
<li><a href="http://www.trasion.com/index.html" rel="gotsubmenu">Homepage</a></li>
<li><a href="http://www.trasion.com/communityforum/" rel="gotsubmenu">Community</a></li>
<li><a href="http://www.trasion.com/software.html" rel="gotsubmenu">Software</a></li>
<li><a href="http://www.trasion.com/customise.html" rel="gotsubmenu">Customise</a></li>
<li><a href="http://www.trasion.com/supportforum/" rel="gotsubmenu">Blogs</a></li>
<li><a href="http://www.trasion.com/developers.html" rel="gotsubmenu">Developers</a></li>
<li><a href="http://www.trasion.com/contactus.html" rel="gotsubmenu">Contact Us</a></li>
</ul>
</div>
</div>
<div class="tabsmenucontentclass">
 </div></center>

<div class="content_border" style="text-align:left"><div class="content">


	<!-- BEGIN_TOP_LINKS -->
	<!-- BEGIN_GUEST_TOP_LINKS -->
	<div style="width:auto;border:#737373 solid 1px;border-top:0px;border-bottom:0px;padding:8px;padding-left:4px;padding-right:4px;font-family:tahoma;font-size:8pt;height:14px;background-color:#EEEEEE;" align="left">
		<span style="margin-left:10px;float:left"><b><a href="search.php">Search</a></b> | <b>$login_link</b> | Current Time is $current_time</span>
		<span style="margin-right:10px;float:right"><b>$register_link</b></span>
	</div>
	
	<div class="navigate" style="width:auto;border:#737373 solid 1px;border-top:0px;padding:4px;font-family:tahoma;font-size:8pt;height:14px;background-color:#e6e6e6">
	<span style="margin-left:10px;font-weight:bold;float:left">$navigate</span>
	<span style="margin-right:10px;font-weight:bold;float:right"></span>
	</div>
	<!-- END_GUEST_TOP_LINKS -->
	
	<!-- BEGIN_REGISTERED_TOP_LINKS -->
	<div style="width:auto;border:#737373 solid 1px;border-top:0px;border-bottom:0px;padding:8px;padding-left:4px;padding-right:4px;font-family:tahoma;font-size:8pt;height:14px;background-color:#EEEEEE;" align="left">
	
		
		<div align="right" style="width:auto;height:14px;">
		<span style="margin-left:10px;float:left"><b><a href="search.php">Search</a></b> | <b>$user_cp_link</b>
		 | Current Time is $current_time</span>
		<span style="float:right;margin-right:10px;"><b>$signout_link</b></span>
		</div>
				
</div>
<div class="navigate" style="width:auto;border:#737373 solid 1px;border-top:0px;padding:4px;font-family:tahoma;font-size:8pt;height:14px;background-color:#e6e6e6; background-position: bottom;background-repeat:repeat-x" align="left">
	<span style="margin-left:10px;font-weight:bold;float:left">$navigate</span>
	<span style="margin-right:10px;font-weight:bold;float:right"></span>
	</div>
	<!-- END_REGISTERED_TOP_LINKS -->

	<!-- END_TOP_LINKS -->





	<!-- BEGIN_ERROR_REPORT -->
	<div class="error_div" align="left">
		<!-- BEGIN_ERROR_ITEM -->
			<li>$error_item</li>
		<!-- END_ERROR_ITEM -->
	</div>
	<!-- END_ERROR_REPORT -->
	
	
	<!-- BEGIN_DONE_REPORT -->
	<div class="done_div" align="left">
		<!-- BEGIN_DONE_ITEM -->
			<li>$error_item</li>
		<!-- END_DONE_ITEM -->
	</div>
	<!-- END_DONE_REPORT -->

If I edit it, it changes to:

Code:
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>site- $title</title>
<meta http-equiv=\"keywords\" content=\"$keyword\" />
<meta http-equiv=\"description\" content=\"$description\" />
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$encoding\" />
</head>
<body>

<script src=\"languages/$language.js\" type=\"text/javascript\"></script>
<script src=\"javascript/aliboard.js\" type=\"text/javascript\"></script>
<script type=\"text/javascript\">
	<!-- JAVASCRIPT_CODES -->
</script>

<link href=\"themes/default/stylesheet/main-style.css\" rel=\"stylesheet\" type=\"text/css\" />

<div style=\"width:auto;\" align=\"center\">
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">
	<tr>
		<td>
	
	
	<center>
	<div class=\"header\"></div>
	<div class=\"navigation_border\">
<div id=\"mytabsmenu\" class=\"tabsmenuclass\">
<ul>
<li><a href=\"http://www.trasion.com/index.html\" rel=\"gotsubmenu\">Homepage</a></li>
<li><a href=\"http://www.trasion.com/communityforum/\" rel=\"gotsubmenu\">Community</a></li>
<li><a href=\"http://www.trasion.com/software.html\" rel=\"gotsubmenu\">Software</a></li>
<li><a href=\"http://www.trasion.com/customise.html\" rel=\"gotsubmenu\">Customise</a></li>
<li><a href=\"http://www.trasion.com/supportforum/\" rel=\"gotsubmenu\">Blogs</a></li>
<li><a href=\"http://www.trasion.com/developers.html\" rel=\"gotsubmenu\">Developers</a></li>
<li><a href=\"http://www.trasion.com/contactus.html\" rel=\"gotsubmenu\">Contact Us</a></li>
</ul>
</div>
</div>
<div class=\"tabsmenucontentclass\">
 </div></center>

<div class=\"content_border\" style=\"text-align:left\"><div class=\"content\">


	<!-- BEGIN_TOP_LINKS -->
	<!-- BEGIN_GUEST_TOP_LINKS -->
	<div style=\"width:auto;border:#737373 solid 1px;border-top:0px;border-bottom:0px;padding:8px;padding-left:4px;padding-right:4px;font-family:tahoma;font-size:8pt;height:14px;background-color:#EEEEEE;\" align=\"left\">
		<span style=\"margin-left:10px;float:left\"><b><a href=\"search.php\">Search</a></b> | <b>$login_link</b> | Current Time is $current_time</span>
		<span style=\"margin-right:10px;float:right\"><b>$register_link</b></span>
	</div>
	
	<div class=\"navigate\" style=\"width:auto;border:#737373 solid 1px;border-top:0px;padding:4px;font-family:tahoma;font-size:8pt;height:14px;background-color:#e6e6e6\">
	<span style=\"margin-left:10px;font-weight:bold;float:left\">$navigate</span>
	<span style=\"margin-right:10px;font-weight:bold;float:right\"></span>
	</div>
	<!-- END_GUEST_TOP_LINKS -->
	
	<!-- BEGIN_REGISTERED_TOP_LINKS -->
	<div style=\"width:auto;border:#737373 solid 1px;border-top:0px;border-bottom:0px;padding:8px;padding-left:4px;padding-right:4px;font-family:tahoma;font-size:8pt;height:14px;background-color:#EEEEEE;\" align=\"left\">
	
		
		<div align=\"right\" style=\"width:auto;height:14px;\">
		<span style=\"margin-left:10px;float:left\"><b><a href=\"search.php\">Search</a></b> | <b>$user_cp_link</b>
		 | Current Time is $current_time</span>
		<span style=\"float:right;margin-right:10px;\"><b>$signout_link</b></span>
		</div>
				
</div>
<div class=\"navigate\" style=\"width:auto;border:#737373 solid 1px;border-top:0px;padding:4px;font-family:tahoma;font-size:8pt;height:14px;background-color:#e6e6e6; background-position: bottom;background-repeat:repeat-x\" align=\"left\">
	<span style=\"margin-left:10px;font-weight:bold;float:left\">$navigate</span>
	<span style=\"margin-right:10px;font-weight:bold;float:right\"></span>
	</div>
	<!-- END_REGISTERED_TOP_LINKS -->

	<!-- END_TOP_LINKS -->





	<!-- BEGIN_ERROR_REPORT -->
	<div class=\"error_div\" align=\"left\">
		<!-- BEGIN_ERROR_ITEM -->
			<li>$error_item</li>
		<!-- END_ERROR_ITEM -->
	</div>
	<!-- END_ERROR_REPORT -->
	
	
	<!-- BEGIN_DONE_REPORT -->
	<div class=\"done_div\" align=\"left\">
		<!-- BEGIN_DONE_ITEM -->
			<li>$error_item</li>
		<!-- END_DONE_ITEM -->
	</div>
	<!-- END_DONE_REPORT -->

And messes up the whole website header...

Excuse me, I forgot to add stripclashes.

Code:
<?php
      if(isset($_POST['submit']))
          {
            $file = "theme/file.html";
            $handle = fopen($file, 'w');
            $data = [B]stripcslashes($_POST['string']);[/B]
            fwrite($handle, $data);
            print "Data Written!";
            fclose($handle);
          }
      $file = "theme/file.html";
      $data = file_get_contents($file);
?>
 
I use file_get_contents() and file_put_contents(). It's the same thing, and if your PHP version doesn't support it, you can use this function to use it:
PHP:
if(!function_exists(file_put_contents) || phpversion()<5)
{
	define('FILE_APPEND', 1);
	function file_put_contents($n, $d, $flag = false) {
		$mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
		$f = @fopen($n, $mode);
		if ($f === false) {
			return 0;
		} else {
			if (is_array($d)) $d = implode($d);
			$bytes_written = fwrite($f, $d);
			fclose($f);
			return $bytes_written;
		}
	}
}
Code from http://us.php.net/manual/en/function.file-put-contents.php#68329
 
With this, what stops me from editing other peoples webpages? Can't I enter the filename like... http://www.forum.ragezone.com/index.php? And edit the page?

Could someone explain to me why I can't do this? Or can I?

You can't put contents on a site without permission. It is possible to get contents from a web-page, but you can't see the server-side scripts unless you use a localized path. That's what makes it safe.

So if you use file_get_contents('http://ragezone.com'), it would do the same as viewing the source code within that function. Now if you did a full URL to one of your pages, it'd do the same thing. So you must use a local path to see the PHP. If you use a full path, the PHP gets translated first. With that said, you can't use a local path to get to ragezone, so you'll never see the PHP behind it. :thumbup:
 
Back