na beveiligen pagina verschijnt tiny_mce editor niet meer!

Status
Niet open voor verdere reacties.

peps03

Gebruiker
Lid geworden
20 nov 2009
Berichten
93
Hoi,

ik heb het volgende script als basis gebruikt en aangepast: http://www.tero.co.uk/scripts/onepagecms.php

ik heb onder andere de standaard beveiliging verwijderd, deze gaf wat problemen. de onderstaande code heb ik voor de beveiliging toegevoegd.
Sinds ik deze code heb toegevoegd verschijnen de knoppen van de tiny_mce editor niet meer. Verder werkt alles goed, ook de beveiliging (vraagt zelfs om een nieuwe login wanneer men op back drukt ;))
wanneer ik de beveiliging weg haal werkt ook alles weer, maar hoe krijg ik beide nu aan het werk?

in ie8 krijg ik deze foutmelding te zien:

Message: Syntax error
Line: 1
Char: 1
Code: 0
URI: http://******.nl/cms/index.php/EDITOR/jscripts/tiny_mce/tiny_mce.js


PHP:
session_start();
////////////////////////////// edit username & password //////////////////////////////////////
$username = "test";
$password = "*********";
//////////////////////////////////////////////////////////////////////////////////////////////
if(isset($_GET['logout']))
{
  unset($_SESSION["login"]);
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://". BASE_URL ."cms/logout/\" />";
  exit;
}

if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_SESSION["login"]) || !isset($_SESSION['realm'])) 
{
  $_SESSION['realm'] = mt_rand( 1, 10000 )." @ ". SITETITLE .
  header("WWW-Authenticate: Basic realm=".$_SESSION['realm']);
  header("HTTP/1.0 401 Unauthorized");
  $_SESSION["login"] = true;
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://". BASE_URL ."cms/logout-wrong/\" />";
  exit;
}
else
{
  if($_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password)
  {
    echo "<p><h1>".SITETITLE." - CMS</h1><p>Je bent ingelogd als: $username [<a href='" . $_SERVER['PHP_SELF'] . "?logout'  class=\"menu\">Logout</a>] OF: Sluit de browser om uit te loggen. [<a href=\"index.php\" target=\"_self\" class=\"menu\">Terug naar het overzicht</a>]</p>";
  }
  else
  {
    unset($_SESSION["login"]);
    header("Location: " . $_SERVER['PHP_SELF']);
  }
}


Of moet ik het hele script even posten? (300regels)

Wat hulp zou ik erg waarderen want ik ben er al een week 8-| mee bezig!

Alvast bedankt!
 
het zal er ongeveer zo uitzien

PHP:
session_start();
////////////////////////////// edit username & password //////////////////////////////////////
$username = "test";
$password = "*********";
//////////////////////////////////////////////////////////////////////////////////////////////
if(isset($_GET['logout'])){
  unset($_SESSION["login"]);
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://". BASE_URL ."cms/logout/\" />";
  exit;
}
 
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_SESSION["login"]) || !isset($_SESSION['realm'])) {
  $_SESSION['realm'] = mt_rand( 1, 10000 )." @ ". SITETITLE .
  header("WWW-Authenticate: Basic realm=".$_SESSION['realm']);
  header("HTTP/1.0 401 Unauthorized");
  $_SESSION["login"] = true;
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://". BASE_URL ."cms/logout-wrong/\" />";
  exit;
}else{
  if($_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password){
    echo "<p><h1>".SITETITLE." - CMS</h1>";
	echo "<p>Je bent ingelogd als: $username [<a href='" . $_SERVER['PHP_SELF'] . "?logout'  class=\"menu\">Logout</a>]";
	echo " OF: Sluit de browser om uit te loggen. [<a href=\"index.php\" target=\"_self\" class=\"menu\">Terug naar het overzicht</a>]</p>";
  }else{
    unset($_SESSION["login"]);
    header("Location: " . $_SERVER['PHP_SELF']);
  }
}
if ($islogin){
	<script type="text/javascript" src="<your installation path>/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example content CSS (should be your site CSS)
content_css : "css/example.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "js/template_list.js",
external_link_list_url : "js/link_list.js",
external_image_list_url : "js/image_list.js",
media_external_list_url : "js/media_list.js",
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
<form method="post" action="somepage">
<textarea name="content" style="width:100%">
</textarea>
<
 
Hoi kenikavanbis!

Bedankt voor de reactie! Het ligt net iets anders dan jij weergeeft. (ik had misschien beter meteen het hele script moeten posten voor de duidelijkheid!)

Maar de TinyMCE editor wordt er via hun eigen site ingeladen, in dit index bestand zeg maar.

Wanneer je html bestanden in de map html zet met deze code om de te editen stukken:
<!--ONEPAGECMS-START-LEFT-COLUMN--> and <!--ONEPAGECMS-END-->
kan je het via dit bestand in de tekstarea via de TinyMCE editor aanpassen.

nu het grote probleem:

Wanneer je dit bestand draait met deze beveiligingscode (zie onder, onder BEVEILIGEN) verschijnt de editor dus niet in het tekst area, wanneer je de beveiligingscode weg haalt, dan wel..

Ik heb het idee dat het iets met de header te maken heeft, zou dat kunnen? omdat er verder in het bestand onder:
/////////////////////////////// Advanced editor ///////////////////////////////
ook een paar keer "header" staat..

Alvast erg bedank!

MvG



PHP:
<?
session_start();
//One Page CMS - written by Paul Tero 23/1/2009. This simple CMS allows you to edit
//text within HTML and PHP pages which appear between comments that look like:
//<!--ONEPAGECMS-START-LEFT-COLUMN--> and <!--ONEPAGECMS-END-->.
//See http://www.tero.co.uk/scripts/onepagecms.php for more information
//From 7/12/2009 this editor can also handle images!
//Specify which files are allowed to be edited. This accepts wildcards and can be an array, eg:
//$ALLOWEDFILES = array ("home/*.php", "about/*.html");
$ALLOWEDFILES = 'html/*.html';
//Directory where we should save backups every time a file is edited. Leave blank to disable this feature
$BACKUPDIR = 'cmsbackups/';
//Directory where images should be (or are already) stored. Leave blank to disable this feature.
$IMAGEDIR = 'cmsimages/';
//If we want to use the TinyMCE editor, pass in the theme. Can be blank for no editor, simple, or advanced.
//Note that this uses the Javascript files from the TinyMCE server, with some extra code to allow popups
//and inserting images to work.
$HTMLEDITOR = 'advanced'; //leave blank to disable
//Site name
define ("SITETITLE", "Test");
//HR (horizontal line width)
define ("HRWIDTH", "825px");
//Site base url
define ("BASE_URL", "*************.nl/");
////////////////////////////// BEVEILIGING ///////////////////////////////////////////////////
////////////////////////////// edit username & password //////////////////////////////////////
$username = "test";
$password = "test";
//////////////////////////////////////////////////////////////////////////////////////////////
if(isset($_GET['logout'])){
  unset($_SESSION["login"]);
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://". BASE_URL ."cms/logout/\" />";
  exit;
}
 
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_SESSION["login"]) || !isset($_SESSION['realm'])) {
  $_SESSION['realm'] = mt_rand( 1, 10000 )." @ ". SITETITLE .
  header("WWW-Authenticate: Basic realm=".$_SESSION['realm']);
  header("HTTP/1.0 401 Unauthorized");
  $_SESSION["login"] = true;
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://". BASE_URL ."cms/logout-wrong/\" />";
  exit;
}else{
  if($_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password){
    echo "<p><h1>".SITETITLE." - CMS</h1>";
    echo "<p>Je bent ingelogd als: $username [<a href='" . $_SERVER['PHP_SELF'] . "?logout'  class=\"menu\">Logout</a>]";
    echo " OF: Sluit de browser om uit te loggen. [<a href=\"index.php\" target=\"_self\" class=\"menu\">Terug naar het overzicht</a>]</p>";
  }else{
    unset($_SESSION["login"]);
    header("Location: " . $_SERVER['PHP_SELF']);
  }
}
echo "<hr width=" .HRWIDTH. " align=\"left\">";
/////////////////////////////// Helpful functions ///////////////////////////////
//This gets all files matching $match. It looks recursively using glob or the find command.
function GetMatchingFiles ($matches) {
	if (!is_array ($matches)) $matches = array ($matches); //the things to match
	$files = array(); //the array of files
	foreach ($matches as $match) {
		//if the glob function exists
		if (function_exists ("glob") && ($globfiles = glob ($match)) && is_array ($globfiles)) $files = array_merge ($files, $globfiles);
		//or else use the find function
		else if (exec ('find . -type f | grep "' . str_replace ('*', '.*', str_replace ('.', '\.', $match)) . '"', $findfiles) && is_array ($findfiles)) $files = array_merge ($files, $findfiles);
		//or else just add the file
		else array_push ($files, $match);
	}
	return $files;
}


//Get the image files from a directory and its subdirectories
function GetImageFiles ($imagedir) { 
	$imageendings = array ('gif', 'jpg', 'jpeg', 'png');
	$a = array(); foreach ($imageendings as $ending) $a = array_merge ($a, GetMatchingFiles ("$imagedir*.$ending"));
	$images = array(); foreach ($a as $image) $images[$image] = preg_replace ("|^$imagedir|", '', $image); //with and without the directory
	return $images;
}

//This gets the editable areas from a file
function GetEditableAreas ($file) {
	$areas = array(); //this is an array of editable areas
	$fc = file_get_contents ($file); //get the file conents
	//Get all the editable areas, s is so that . matches multiline, U is for ungreedy
	preg_match_all ('/<!--ONEPAGECMS-START-([\w\d-]+)-->(.*)<!--ONEPAGECMS-END-->/sU', $fc, $matches, PREG_SET_ORDER);
	//Loop through the matches and put them into an array, also removing any \r characters that might get entered
	foreach ($matches as $m) array_push ($areas, array (ucwords (str_replace ('-', ' ', $m[1])), $m[2]));
	//Return the editable areas which is an array of arrays each with 2 elements for the name and text
	return $areas;
}

//For saving a file
function SaveFile ($file, $areas, $backupdir='') {
	//First check we can save the data
	if (!$areas) return "Er is geen data om op te slaan!";
	$fc = file_get_contents ($file); //get the file conents
	if (!$fc) return "Kan het bestand: $file niet lezen";
	//Now get allthe parts with tags
	$parts = preg_split ('/(<!--ONEPAGECMS-[\w\d-]+-->)/', $fc, -1, PREG_SPLIT_DELIM_CAPTURE); //split by the ONEPAGECMS tags
	if (count ($parts) != count ($areas) * 4 + 1) return "Er zijn een verkeerd aantal ONEPAGECMS tags in het bestand";
	$newcontents = array_shift ($parts); //get the first bit before the first ONEPAGECMS tag
	//For each editable area, get the START tag, the editable area, the end tag, then the part after the END tag
	foreach ($areas as $i=>$area) //remove slashes and \r from the data being saved
		$newcontents .= $parts[$i*4] . "\n" . trim (stripSlashes (preg_replace ("/\r\n?/", "\n", $areas[$i]))) . "\n" .
			$parts[$i*4 + 2] . $parts[$i*4+3];
	//Backup the file before saving it, and make the backup world writeable so it can be deleted via FTP
	if ($backupdir) {
		if (!is_dir ($backupdir)) {mkdir ($backupdir); chmod ($backupdir, 0777);}
		copy ($file, $backupfile = $backupdir . '/' . str_replace ('/', '-', $file) . '.' . date ('Y-m-d-Hi') . '.backup');
		if (file_exists ($backupfile)) chmod ($backupfile, 0666);
	}
	//Save the contents
	$fw = fopen ($file, 'w'); //try to open the file for writing
	if (!$fw) return "Kan de gewijzigde data in het bestand $file niet wegschrijven. Check of er voldoende rechten zijn.";
	//Save the file
	fwrite ($fw, $newcontents); fclose ($fw);
	return "Bestand is succesvol opgeslagen.";
}

//Saving the images
function SaveImages ($imagedir) {
	$imageendings = array ('gif', 'jpg', 'jpeg', 'png'); $m = array();
	if (!is_dir ($imagedir)) {mkdir ($imagedir); chmod ($imagedir, 0777);}
	//Check it's the right endings, etc
	if (isset ($_POST['remove'])) foreach ($_POST['remove'] as $image) 
		if (preg_match ("~^$imagedir.+\." . join ('|', $imageendings) . '$~', $image)) {$m[] = "Bezig $image te verwijderen"; unlink ($image);}
		else $m[] = "Kan $image niet verwijderen (misschien door de bestandsextensie)";
	foreach ($_FILES as $formfield=>$filedata) {
		if (!$filedata['size']) continue; //nothing to upload
		$moveto = $imagedir . $filedata['name'];
		if ($filedata['error']) $m[] = "Kan $filedata[name] niet uploaden omdat: $filedata[error]";
		else if (!preg_match ('~\.' . join ('|', $imageendings) . '$~', $filedata['name'])) $m[] = "Kan $filedata[name] niet uploaden. (Verkeerde bestandsextensie)";
		else {$m[] = "Saving $moveto"; move_uploaded_file ($filedata['tmp_name'], $moveto); chmod ($moveto, 0666);}
	}
	return join ('<br/>', $m);
}

/////////////////////////////// Advanced editor ///////////////////////////////
//This code helps make the advanced TinyMCE editor work. When using the advanced editor, all files required from the editor
//are passed through onepagecms.php first. This means they will all appear to be coming from the local domain and avoids
//Javascript security alerts and problems. It also means that I can hack the image inserter so that it shows a drop down
//list of images from $IMAGEDIR.
function ProcessEditor ($imagedir) {
	if (!preg_match ('|EDITOR/(.*)$|', $_SERVER['REQUEST_URI'], $ed)) return;
	if (preg_match ('/css$/', $ed[1])) header ("Content-type: text/css"); //output the mime type header for CSS files
	//If this has been requested before (or it's image.htm), then just return the Cached version
	if (basename ($ed[1]) != 'image.htm' && isset ($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { //it's been requested before
		header ("Expires: Sat, 6 Mar 1976 10:00:00 GMT"); //expire the page at some time in the past
		header ("Cache-Control: private, must-revalidate"); //let them cache it
		header ("Pragma: cache"); //override the default header to reallow caching
		header ("HTTP/1.0 304 Not Modified");
		exit;
	}
	//Or else get the file contents over the Internet and return them
	$contents = file_get_contents ('http://tinymce.moxiecode.com/js/tinymce/' . rawurldecode ($ed[1])); //get the contents of the file
	if (basename ($ed[1]) == 'image.htm' && ($idpos = strpos ($contents, 'id="src"'))) { //this is the image uploading HTML file
		$select = '<tr><td><label for="image_list2">Or choose from</label></td><td><select id="image_list2" name="image_list2" onchange="document.getElementById(\'src\').value=this.options[this.selectedIndex].value;"><option value="">choose one</option>';
		$images = GetImageFiles ($imagedir); //the images to put in the drop down
		foreach ($images as $src=>$image) $select .= '<option value="' . $src. '">' . $image . '</option>';
		$select .= '</select></td></tr>';
		$trpos = strpos ($contents, '<tr>', $idpos);
		if ($images && $trpos) $contents = substr ($contents, 0, $trpos) . $select . substr ($contents, $trpos);
	} else header ("Last-Modified: " . gmdate ("D, d M Y H:i:s")); //send now as the last modified date
	echo $contents; 
	exit;
}
ProcessEditor ($IMAGEDIR);


/////////////////////////////// Outputting the page ///////////////////////////////
function OutputPage ($allowedfiles, $backupdir='', $htmleditor='', $imagedir='') {
	$me = $_SERVER['SCRIPT_NAME']; //my page nmae
	$areawidth = 100; //the width in columns of the text area
	$filestoedit = GetMatchingFiles ($allowedfiles); //files I am allowed to edit
	$imagemanager = isset ($_GET['imagemanager']) ? $_GET['imagemanager'] : ''; //should we show the image manager
	$editfile = isset ($_GET['file']) ? $_GET['file'] : ''; //the file they want to edit
	if (!in_array ($editfile, $filestoedit)) $editfile = ''; //the file must be in the array of allowed files
	$editareas = $editfile ? GetEditableAreas ($editfile) : array(); //the areas to edit
	$saveimages = isset ($_POST['imagemanager']) ? $_POST['imagemanager'] : ''; //if there are images to save
	if ($saveimages) $imagemanager = true; //we should view the image manager if saving images
	$savefile = isset ($_POST['file']) ? $_POST['file'] : ''; //if there is a file to save
	if (!in_array ($savefile, $filestoedit)) $savefile = ''; //the file must be in the array of allowed files
	$saveareas = $savefile && isset ($_POST['areas']) ? $_POST['areas'] : array(); //areas of the page to save
?>
<html>
<head>
<style type="text/css">
<!--
@import url("http://<?PHP echo BASE_URL ?>cms/scripts/style.css");
-->
</style>
<title><?PHP echo SITETITLE ?> - CMS</title>
<? if ($htmleditor) {$editorprefix = $htmleditor=='advanced' ? "$me/EDITOR/" : 'http://tinymce.moxiecode.com/js/tinymce/'; //for the HTML editor ?>
<script type="text/javascript" src="<?=$editorprefix?>jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">tinyMCE.init({mode : 'textareas', theme : '<?=$htmleditor?>'});</script>
<? } ?>
</head>
<body>
<h2>Beheer html</h2>
<p>
Hieronder staat een overzicht van de pagina's waarop velden staan die je kan aanpassen.<br />
</p>
<ul>
<?	foreach ($filestoedit as $listfile) if (basename ($me) != basename ($listfile)) { ?>
<li><a href="<?=$me?>?file=<?=$listfile?>"><?=$listfile?></a> (<a href="<?=$listfile?>">Bekijk</a>)</li>
<?	} ?>
<?	if ($imagedir) { ?><li><a href="<?=$me?>?imagemanager=yes">Beheer images</a></li><? } //a link to the image manager ?>
</ul><br />
<? ////////////////////////////////////////////////////////////////////AUDIO/////////////////////////////////////////////?>
<hr width="<?PHP echo HRWIDTH ?>" align="left">
<h2>Beheer audio</h2>
<p>Hieronder kan een mp3 bestand geselecteerd worden om te uploaden, max 10mb.<br /><br /></p>
<?php
echo "<form method='post' enctype='multipart/form-data'><input type='file' name='file' width='300px'>&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='upload1' value='Upload'> </form>";
$map = "audio/";  //map waar die in komt (wel chmod permision 777 geven 
if(isset($_POST['upload1'])) { 
  if($_FILES['file']['size'] <= 1024*10000) {  
    // Controle of het bestand groter is als 10 mb (tussen de [''] van $_FILES vul je de naam van het veld in) 
    $extension = array(); 
    $extension[] = "audio/mp3";  // zet de extensions (vb: .jpg) in de array..  
    $extension[] = "audio/mpeg";  // altijd met audio/ ervoor en zonder punt 
    // Let op .jpg kan hij verschillend zien (bv: ook als .pjpg) zoek dus op internet een lijst anders krijg je vaak errors.. 
    if(in_array($_FILES['file']['type'], $extension)) { 
    // Controle of hij een bestand met de juiste extension heeft geupload 
      if(is_uploaded_file($_FILES['file']['tmp_name'])) {  //Contorleren of hij is geupload 
        move_uploaded_file($_FILES['file']['tmp_name'], $map.$_FILES['file']['name']); 
        // eerst geef je de file aan met de tmp naam waar die tijdelijk staat op geslagen, daarna de mapnaam en de filenaam met een punt er tussen  
        echo "<p><span style=\"color:#F00\">Bestand succesvol geupload..</span></p>"; 
      } else { 
        echo "<p><span style=\"color:#F00\">Er is iets mis gegaan bij het uploaden, probeer het nogmaals</span></p>"; 
      } 
    } else { 
      echo "<p><span style=\"color:#F00\">Het bestand heeft een verkeerde extensie</span></p>"; 
    } 
  } else { 
    echo "<p><span style=\"color:#F00\">Het bestand moet kleiner zijn dan 10 mb</span></p>"; 
  } 
} else { 
// Hier je formulier (deze is zichtbaar wanneer er niet op submit is gedrukt..) 
} 
?>


<?	if ($savefile) { //there is a file to save ?>
<hr width="<?PHP echo HRWIDTH ?>" align="left">
<h2>Wijzigingen opslaan in: <span style="color:#F00"><?=$savefile?></span><br /><br /></h2>
<p>Bezig het volgende bestand op te te slaan: <a href="<?=$me?>?file=<?=$savefile?>"><?=$savefile?></a>
(<a href="<?=$savefile?>">bekijk</a>). Mogelijke foutmeldingen tijdens het opslaan verschijnen hier... <br /><br /></p>
<p><b><?= SaveFile ($savefile, $saveareas, $backupdir) ?></b></p>
<?	} //file to save ?>
<?	if ($editfile) { //there is a file to edit ?>
<br /><br /><hr width="<?PHP echo HRWIDTH ?>" align="left">
<h2>Wijzig het bestand <span style="color:#F00"><?= $editfile?></span></h2>
<p>Wijzig <?=$htmleditor ? 'tekst' : 'HTML'?> in de velden hieronder en sla de wijzigingen dan op!<br /><br />
<div style="width:550px; height:80px; background-color:#F6F6F6; border-style:dashed; border-width:thin; margin-left:150px; padding:3px;">
  <p><b>Om een nummer op de site te plaatsen moet er eerst op -html- worden gedrukt.</b> Dan moet deze code gecopieerd en geplakt worden:<br />
  &lt;p&gt;&lt;a href=&quot;audio/***.mp3&quot;&gt;***&lt;/a&gt;&lt;/p&gt;<br /><br />Op de plek van de *** moet de bestandsnaam worden geplaatst.<br /><br /></p></div>
<form method="post" action="<?=$me?>">
<input name="file" type="hidden" value="<?=$editfile?>" />
<?		if (!$editareas) echo "<p><b>Sorry, maar $editfile heeft geen aan te passen velden.</b></p>"; ?>
<?		foreach ($editareas as $area) {$numlines = $htmleditor ? 20 : substr_count (wordwrap ($area[1], $areawidth), "\n"); ?>
<h3><?=$area[0]?></h3>
<textarea name="areas[]" rows="<?= max ($numlines, 5) ?>" cols="<?=$areawidth?>"><?=$area[1]?></textarea>
<?		} ?>
<br /><br /><hr width="<?PHP echo HRWIDTH ?>" align="left">
<?		if ($editareas) echo '<p><input type="submit" value="Save"/></p><br /><br /><br />'; ?>
</form>
<?	} //file to edit ?>
<?	if ($saveimages) { //saving the images?>
<h2>Saving images</h2>
<p>Saving de images. Mogelijke foutmeldingen tijdens het opslaan verschijnen hier...</p>
<p><b><?= SaveImages ($imagedir) ?></b></p>
<?	} ?>
<?	if ($imagemanager) { //they want to manage iamges ?>
<br /><br /><hr width="<?PHP echo HRWIDTH ?>" align="left">
<h2>Beheer images</h2>
<p>Gebruik de onderstaande links om images te bekijken, verwijderen en uploaden naar: <?=$imagedir?>.</p>
<form method="post" action="<?=$me?>" enctype="multipart/form-data">
<input name="imagemanager" type="hidden" value="yes" />
<ul>
<?	foreach (GetImageFiles ($imagedir) as $src=>$image) { ?>
<li><p><a href="<?=$src?>" target="onepagecms_view"><?=$image?></a> (<input type="checkbox" name="remove[]" value="<?=$src?>"> 
verwijderen?)</p></li>
<?	} ?>
<li><p>Upload een nieuw image: 
  <input type="file" name="newimage1" size="20" /></p></li>
</ul>
<br /><br /><hr width="<?PHP echo HRWIDTH ?>" align="left">
<p><input type="submit" value="Save"/></p><br /><br /><br />
</form>
<?	} ?>
</body>
</html>

<?	
} //finish the output page function


/////////////////////////////// Run the CMS ///////////////////////////////
//Turn on error reporting so the user can see everything like file writing errors
ini_set ('display_errors', 1); error_reporting (E_ALL);
//Output the page
OutputPage ($ALLOWEDFILES, $BACKUPDIR, $HTMLEDITOR, $IMAGEDIR); ?>
 
Laatst bewerkt:
install firefox
install developer toolbar in firefox addons
wat geeft dan de header weer ??
 
oke!
ik heb nu de
web developer toolbar geinstalleerd
en de php developer toolbar,

toen heb ik gedrukt op: view respons headers, kreeg dit te zien:
Date: Wed, 28 Apr 2010 11:27:04 GMT
Server: Apache/2
X-Powered-By: PHP/4.4.9-0.dotdeb.1
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 2481
Content-Type: text/html; charset=iso-8859-1

200 OK


is dit wat je bedoelde?

bedank!
 
Foute van mij
Bekijk volgende functie en vervolgens alle header sender vervangen door de functie Dit als je de fout maakt al iets geprint te hebben zal hij de link tonen met melding dat de header al is verzonden dit gebeurt ook al bij een gewone enter voor de <? tag en maakt OMDAT ik denk dat het een header is dat wordt verstuurt die mogelijks niet bestaat
en verder kan ook tinymce het downloaden verbieden
PHP:
/**
* @author Lieven Roegiers
* @copyright 2007
* @CMS autosite
*/
	function redirect($url){
		if (!headers_sent()){
			//print('Location: http://'.$_SERVER['SERVER_NAME'].$url);
			header('Location: http://'.$_SERVER['SERVER_NAME'].$url);
		}else {
			die('Redirect Headers error to send <a href="http://'.$_SERVER['SERVER_NAME'].$url.'" >here the link</a>');
		}
	}
Bekijk ook de veranderingen van je script zonder functionele verandering toch iets opgekuister lijkt
PHP:
<?
session_start();
//One Page CMS - written by Paul Tero 23/1/2009. This simple CMS allows you to edit
//text within HTML and PHP pages which appear between comments that look like:
//<!--ONEPAGECMS-START-LEFT-COLUMN--> and <!--ONEPAGECMS-END-->.
//See http://www.tero.co.uk/scripts/onepagecms.php for more information
//From 7/12/2009 this editor can also handle images!
//Specify which files are allowed to be edited. This accepts wildcards and can be an array, eg:
//$ALLOWEDFILES = array ("home/*.php", "about/*.html");
$ALLOWEDFILES = 'html/*.html';
//Directory where we should save backups every time a file is edited. Leave blank to disable this feature
$BACKUPDIR = 'cmsbackups/';
//Directory where images should be (or are already) stored. Leave blank to disable this feature.
$IMAGEDIR = 'cmsimages/';
//If we want to use the TinyMCE editor, pass in the theme. Can be blank for no editor, simple, or advanced.
//Note that this uses the Javascript files from the TinyMCE server, with some extra code to allow popups
//and inserting images to work.
$HTMLEDITOR = 'advanced'; //leave blank to disable
//Site name
define ("SITETITLE", "Test");
//HR (horizontal line width)
define ("HRWIDTH", "825px");
//Site base url
define ("BASE_URL", "*************.nl/");
////////////////////////////// BEVEILIGING ///////////////////////////////////////////////////
////////////////////////////// edit username & password //////////////////////////////////////
$username = "test";
$password = "test";
//////////////////////////////////////////////////////////////////////////////////////////////
if(isset($_GET['logout'])){
  unset($_SESSION["login"]);
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://". BASE_URL ."cms/logout/\" />";
  exit;
}
 
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_SESSION["login"]) || !isset($_SESSION['realm'])) {
  $_SESSION['realm'] = mt_rand( 1, 10000 )." @ ". SITETITLE .
  header("WWW-Authenticate: Basic realm=".$_SESSION['realm']);
  header("HTTP/1.0 401 Unauthorized");
  $_SESSION["login"] = true;
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://". BASE_URL ."cms/logout-wrong/\" />";
  exit;
}else{
  if($_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password){
    echo "<p><h1>".SITETITLE." - CMS</h1>";
    echo "<p>Je bent ingelogd als: $username [<a href='" . $_SERVER['PHP_SELF'] . "?logout'  class=\"menu\">Logout</a>]";
    echo " OF: Sluit de browser om uit te loggen. [<a href=\"index.php\" target=\"_self\" class=\"menu\">Terug naar het overzicht</a>]</p>";
  }else{
    unset($_SESSION["login"]);
    header("Location: " . $_SERVER['PHP_SELF']);
  }
}
echo "<hr width=" .HRWIDTH. " align=\"left\">";
/////////////////////////////// Helpful functions ///////////////////////////////
//This gets all files matching $match. It looks recursively using glob or the find command.
function GetMatchingFiles ($matches) {
    if (!is_array ($matches)) $matches = array ($matches); //the things to match
    $files = array(); //the array of files
    foreach ($matches as $match) {
        //if the glob function exists
        if (function_exists ("glob") && ($globfiles = glob ($match)) && is_array ($globfiles)) $files = array_merge ($files, $globfiles);
        //or else use the find function
        else if (exec ('find . -type f | grep "' . str_replace ('*', '.*', str_replace ('.', '\.', $match)) . '"', $findfiles) && is_array ($findfiles)) $files = array_merge ($files, $findfiles);
        //or else just add the file
        else array_push ($files, $match);
    }
    return $files;
}
 
 
//Get the image files from a directory and its subdirectories
function GetImageFiles ($imagedir) { 
    $imageendings = array ('gif', 'jpg', 'jpeg', 'png');
    $a = array(); foreach ($imageendings as $ending) $a = array_merge ($a, GetMatchingFiles ("$imagedir*.$ending"));
    $images = array(); foreach ($a as $image) $images[$image] = preg_replace ("|^$imagedir|", '', $image); //with and without the directory
    return $images;
}
 
//This gets the editable areas from a file
function GetEditableAreas ($file) {
    $areas = array(); //this is an array of editable areas
    $fc = file_get_contents ($file); //get the file conents
    //Get all the editable areas, s is so that . matches multiline, U is for ungreedy
    preg_match_all ('/<!--ONEPAGECMS-START-([\w\d-]+)-->(.*)<!--ONEPAGECMS-END-->/sU', $fc, $matches, PREG_SET_ORDER);
    //Loop through the matches and put them into an array, also removing any \r characters that might get entered
    foreach ($matches as $m) array_push ($areas, array (ucwords (str_replace ('-', ' ', $m[1])), $m[2]));
    //Return the editable areas which is an array of arrays each with 2 elements for the name and text
    return $areas;
}
 
//For saving a file
function SaveFile ($file, $areas, $backupdir='') {
    //First check we can save the data
    if (!$areas) return "Er is geen data om op te slaan!";
    $fc = file_get_contents ($file); //get the file conents
    if (!$fc) return "Kan het bestand: $file niet lezen";
    //Now get allthe parts with tags
    $parts = preg_split ('/(<!--ONEPAGECMS-[\w\d-]+-->)/', $fc, -1, PREG_SPLIT_DELIM_CAPTURE); //split by the ONEPAGECMS tags
    if (count ($parts) != count ($areas) * 4 + 1) return "Er zijn een verkeerd aantal ONEPAGECMS tags in het bestand";
    $newcontents = array_shift ($parts); //get the first bit before the first ONEPAGECMS tag
    //For each editable area, get the START tag, the editable area, the end tag, then the part after the END tag
    foreach ($areas as $i=>$area) //remove slashes and \r from the data being saved
        $newcontents .= $parts[$i*4] . "\n" . trim (stripSlashes (preg_replace ("/\r\n?/", "\n", $areas[$i]))) . "\n" .
            $parts[$i*4 + 2] . $parts[$i*4+3];
    //Backup the file before saving it, and make the backup world writeable so it can be deleted via FTP
    if ($backupdir) {
        if (!is_dir ($backupdir)) {mkdir ($backupdir); chmod ($backupdir, 0777);}
        copy ($file, $backupfile = $backupdir . '/' . str_replace ('/', '-', $file) . '.' . date ('Y-m-d-Hi') . '.backup');
        if (file_exists ($backupfile)) chmod ($backupfile, 0666);
    }
    //Save the contents
    $fw = fopen ($file, 'w'); //try to open the file for writing
    if (!$fw) return "Kan de gewijzigde data in het bestand $file niet wegschrijven. Check of er voldoende rechten zijn.";
    //Save the file
    fwrite ($fw, $newcontents); fclose ($fw);
    return "Bestand is succesvol opgeslagen.";
}
//Saving the images
function SaveImages ($imagedir) {
    $imageendings = array ('gif', 'jpg', 'jpeg', 'png'); $m = array();
    if (!is_dir ($imagedir)) {mkdir ($imagedir); chmod ($imagedir, 0777);}
    //Check it's the right endings, etc
    if (isset ($_POST['remove'])) foreach ($_POST['remove'] as $image) 
        if (preg_match ("~^$imagedir.+\." . join ('|', $imageendings) . '$~', $image)) {$m[] = "Bezig $image te verwijderen"; unlink ($image);}
        else $m[] = "Kan $image niet verwijderen (misschien door de bestandsextensie)";
    foreach ($_FILES as $formfield=>$filedata) {
        if (!$filedata['size']) continue; //nothing to upload
        $moveto = $imagedir . $filedata['name'];
        if ($filedata['error']) $m[] = "Kan $filedata[name] niet uploaden omdat: $filedata[error]";
        else if (!preg_match ('~\.' . join ('|', $imageendings) . '$~', $filedata['name'])) $m[] = "Kan $filedata[name] niet uploaden. (Verkeerde bestandsextensie)";
        else {$m[] = "Saving $moveto"; move_uploaded_file ($filedata['tmp_name'], $moveto); chmod ($moveto, 0666);}
    }
    return join ('<br/>', $m);
}
/////////////////////////////// Advanced editor ///////////////////////////////
//This code helps make the advanced TinyMCE editor work. When using the advanced editor, all files required from the editor
//are passed through onepagecms.php first. This means they will all appear to be coming from the local domain and avoids
//Javascript security alerts and problems. It also means that I can hack the image inserter so that it shows a drop down
//list of images from $IMAGEDIR.
function ProcessEditor ($imagedir) {
    if (!preg_match ('|EDITOR/(.*)$|', $_SERVER['REQUEST_URI'], $ed)) return;
    if (preg_match ('/css$/', $ed[1])) header ("Content-type: text/css"); //output the mime type header for CSS files
    //If this has been requested before (or it's image.htm), then just return the Cached version
    if (basename ($ed[1]) != 'image.htm' && isset ($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { //it's been requested before
        header ("Expires: Sat, 6 Mar 1976 10:00:00 GMT"); //expire the page at some time in the past
        header ("Cache-Control: private, must-revalidate"); //let them cache it
        header ("Pragma: cache"); //override the default header to reallow caching
        header ("HTTP/1.0 304 Not Modified");
        exit;
    }
    //Or else get the file contents over the Internet and return them
    $contents = file_get_contents ('http://tinymce.moxiecode.com/js/tinymce/' . rawurldecode ($ed[1])); //get the contents of the file
    if (basename ($ed[1]) == 'image.htm' && ($idpos = strpos ($contents, 'id="src"'))) { //this is the image uploading HTML file
        $select = '<tr><td><label for="image_list2">Or choose from</label></td><td><select id="image_list2" name="image_list2" onchange="document.getElementById(\'src\').value=this.options[this.selectedIndex].value;"><option value="">choose one</option>';
        $images = GetImageFiles ($imagedir); //the images to put in the drop down
        foreach ($images as $src=>$image) $select .= '<option value="' . $src. '">' . $image . '</option>';
        $select .= '</select></td></tr>';
        $trpos = strpos ($contents, '<tr>', $idpos);
        if ($images && $trpos) $contents = substr ($contents, 0, $trpos) . $select . substr ($contents, $trpos);
    } else header ("Last-Modified: " . gmdate ("D, d M Y H:i:s")); //send now as the last modified date
    echo $contents; 
    exit;
}
ProcessEditor ($IMAGEDIR); 
/////////////////////////////// Outputting the page ///////////////////////////////
function OutputPage ($allowedfiles, $backupdir='', $htmleditor='', $imagedir='') {
    $me = $_SERVER['SCRIPT_NAME']; //my page nmae
    $areawidth = 100; //the width in columns of the text area
    $filestoedit = GetMatchingFiles ($allowedfiles); //files I am allowed to edit
    $imagemanager = isset ($_GET['imagemanager']) ? $_GET['imagemanager'] : ''; //should we show the image manager
    $editfile = isset ($_GET['file']) ? $_GET['file'] : ''; //the file they want to edit
    if (!in_array ($editfile, $filestoedit)) $editfile = ''; //the file must be in the array of allowed files
    $editareas = $editfile ? GetEditableAreas ($editfile) : array(); //the areas to edit
    $saveimages = isset ($_POST['imagemanager']) ? $_POST['imagemanager'] : ''; //if there are images to save
    if ($saveimages) $imagemanager = true; //we should view the image manager if saving images
    $savefile = isset ($_POST['file']) ? $_POST['file'] : ''; //if there is a file to save
    if (!in_array ($savefile, $filestoedit)) $savefile = ''; //the file must be in the array of allowed files
    $saveareas = $savefile && isset ($_POST['areas']) ? $_POST['areas'] : array(); //areas of the page to save
?>
<html>
<head>
<style type="text/css">
<!--
@import url("http://<?PHP echo BASE_URL ?>cms/scripts/style.css");
-->
</style>

<title><?PHP echo SITETITLE ?> - CMS</title>
<? if ($htmleditor) {$editorprefix = $htmleditor=='advanced' ? "$me/EDITOR/" : 'http://tinymce.moxiecode.com/js/tinymce/'; //for the HTML editor ?>
<script type="text/javascript" src="<?=$editorprefix?>jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">tinyMCE.init({mode : 'textareas', theme : '<?=$htmleditor?>'});</script>
<? } ?>
</head>
<body>
<h2>Beheer html</h2>
<p>
Hieronder staat een overzicht van de pagina's waarop velden staan die je kan aanpassen.<br />
</p>
<ul>
<?  foreach ($filestoedit as $listfile) if (basename ($me) != basename ($listfile)) { ?>
<li><a href="<?=$me?>?file=<?=$listfile?>"><?=$listfile?></a> (<a href="<?=$listfile?>">Bekijk</a>)</li>
<?  } 
  if ($imagedir) { print"<li><a href='".$me."?imagemanager=yes'>Beheer images</a></li>" } //a link to the image manager ?>
</ul><br />
<? /** /////////////////////////////////////////////////////////////////AUDIO///////////////////////////////////////////*/?>
<hr width="<?PHP echo HRWIDTH ?>" align="left">
<h2>Beheer audio</h2>
<p>Hieronder kan een mp3 bestand geselecteerd worden om te uploaden, max 10mb.<br /><br /></p>
<?php
echo "<form method='post' enctype='multipart/form-data'><input type='file' name='file' width='300px'>&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='upload1' value='Upload'> </form>";
$map = "audio/";  //map waar die in komt (wel chmod permision 777 geven 
if(isset($_POST['upload1'])) { 
  if($_FILES['file']['size'] <= 1024*10000) {  
    // Controle of het bestand groter is als 10 mb (tussen de [''] van $_FILES vul je de naam van het veld in) 
    $extension = array(); 
    $extension[] = "audio/mp3";  // zet de extensions (vb: .jpg) in de array..  
    $extension[] = "audio/mpeg";  // altijd met audio/ ervoor en zonder punt 
    // Let op .jpg kan hij verschillend zien (bv: ook als .pjpg) zoek dus op internet een lijst anders krijg je vaak errors.. 
    if(in_array($_FILES['file']['type'], $extension)) { 
    // Controle of hij een bestand met de juiste extension heeft geupload 
      if(is_uploaded_file($_FILES['file']['tmp_name'])) {  //Contorleren of hij is geupload 
        move_uploaded_file($_FILES['file']['tmp_name'], $map.$_FILES['file']['name']); 
        // eerst geef je de file aan met de tmp naam waar die tijdelijk staat op geslagen, daarna de mapnaam en de filenaam met een punt er tussen  
        echo "<p><span style=\"color:#F00\">Bestand succesvol geupload..</span></p>"; 
      } else { 
        echo "<p><span style=\"color:#F00\">Er is iets mis gegaan bij het uploaden, probeer het nogmaals</span></p>"; 
      } 
    } else { 
      echo "<p><span style=\"color:#F00\">Het bestand heeft een verkeerde extensie</span></p>"; 
    } 
  } else { 
    echo "<p><span style=\"color:#F00\">Het bestand moet kleiner zijn dan 10 mb</span></p>"; 
  } 
} else { 
// Hier je formulier (deze is zichtbaar wanneer er niet op submit is gedrukt..) 
} 


if ($savefile) { //there is a file to save ?>
<hr width="<?PHP echo HRWIDTH ?>" align="left">
<h2>Wijzigingen opslaan in: <span style="color:#F00"><?=$savefile?></span><br /><br /></h2>
<p>Bezig het volgende bestand op te te slaan: <a href="<?=$me?>?file=<?=$savefile?>"><?=$savefile?></a>
(<a href="<?=$savefile?>">bekijk</a>). Mogelijke foutmeldingen tijdens het opslaan verschijnen hier... <br /><br /></p>
<p><b><?= SaveFile ($savefile, $saveareas, $backupdir) ?></b></p>
<?  } //file to save 
  if ($editfile) { //there is a file to edit ?>
<br /><br /><hr width="<?PHP echo HRWIDTH ?>" align="left">
<h2>Wijzig het bestand <span style="color:#F00"><?= $editfile?></span></h2>
<p>Wijzig <?=$htmleditor ? 'tekst' : 'HTML'?> in de velden hieronder en sla de wijzigingen dan op!<br /><br />
<div style="width:550px; height:80px; background-color:#F6F6F6; border-style:dashed; border-width:thin; margin-left:150px; padding:3px;">
  <p><b>Om een nummer op de site te plaatsen moet er eerst op -html- worden gedrukt.</b> Dan moet deze code gecopieerd en geplakt worden:<br />
  &lt;p&gt;&lt;a href=&quot;audio/***.mp3&quot;&gt;***&lt;/a&gt;&lt;/p&gt;<br /><br />Op de plek van de *** moet de bestandsnaam worden geplaatst.<br /><br /></p></div>
<form method="post" action="<?=$me?>">
<input name="file" type="hidden" value="<?=$editfile?>" />
<?    if (!$editareas) echo "<p><b>Sorry, maar $editfile heeft geen aan te passen velden.</b></p>"; 
	      foreach ($editareas as $area) {$numlines = $htmleditor ? 20 : substr_count (wordwrap ($area[1], $areawidth), "\n"); 
		      print"<h3>".$area[0]."</h3>";
			  print"<textarea name='".areas[]."' rows='"max($numlines, 5)"' cols='"$areawidth"'>$area[1]</textarea>";
      }
      print "<br /><br /><hr width='".HRWIDTH "' align="left" />";
      if ($editareas) echo '<p><input type="submit" value="Save"/></p><br /><br /><br />'; 
			  print'</form>';
      } //file to edit 
      if ($saveimages) { //saving the images
		?>
		<h2>Saving images</h2>
		<p>Saving de images. Mogelijke foutmeldingen tijdens het opslaan verschijnen hier...</p>
		<p><b><?= SaveImages ($imagedir) ?></b></p>
		<?
	  }
	  if ($imagemanager) { //they want to manage iamges ?>
		<br /><br /><hr width="<?PHP echo HRWIDTH ?>" align="left" />
		<h2>Beheer images</h2>
		<p>Gebruik de onderstaande links om images te bekijken, verwijderen en uploaden naar: <?=$imagedir?>.</p>
		<form method="post" action="<?=$me?>" enctype="multipart/form-data">
		<input name="imagemanager" type="hidden" value="yes" />
		<ul>
		<?  foreach (GetImageFiles ($imagedir) as $src=>$image) {
        print"<li><p><a href='$src' target="onepagecms_view">$image</a>(<input type="checkbox" name="remove[]" value="$src">verwijderen?)</p></li>";
	   } ?>
	<li>Upload een nieuw image: <input type="file" name="newimage1" size="20" /></li>
</ul>
<br /><br />
	<hr width="<?PHP echo HRWIDTH ?>" align="left" />
	<input type="submit" value="Save"/>
	<br /><br /><br />
</form>
<?  }
print" </body></html>";
<?  
} //finish the output page function
//<<<<<<<<<<<<<<<<<<<<<<<Run the CMS>>>>>>>>>>>>>>>>>>>>>>>>>
//Turn on error reporting so the user can see everything like file writing errors
ini_set ('display_errors', 1); error_reporting (E_ALL);
//Output the page
OutputPage ($ALLOWEDFILES, $BACKUPDIR, $HTMLEDITOR, $IMAGEDIR);
?>


Merk op wat het verschill is al je dit doet
zichtbaar in browers
/////////////////////////////// Run the CMS ///////////////////////////////
niet zichtbaar in browser enkel // te zien
//<<<<<<<<<<<<<<<<<<<<<<<Run the CMS>>>>>>>>>>>>>>>>>>>>>>>>>
 
Laatst bewerkt:
Ik begrijp niet precies wat je bedoelt;

ik moet deze code op de plaats zetten van welk stuk code?

PHP:
function redirect($url){
        if (!headers_sent()){
            //print('Location: http://'.$_SERVER['SERVER_NAME'].$url);
            header('Location: http://'.$_SERVER['SERVER_NAME'].$url);
        }else {
            die('Redirect Headers error to send <a href="http://'.$_SERVER['SERVER_NAME'].$url.'" >here the link</a>');
        }
    }

Dit is nog een foutmelding die ik via de toolbar krijg!::

Error: syntax error
Source File: http://*******.nl/cms1/index.php/EDITOR/jscripts/tiny_mce/tiny_mce.js
Line: 1, Column: 72
Source Code:
naar het overzicht</a>]</p><hr width="825px" align="left">(function(c){var a=/^\s*|\s*$/g,d;var b={majorVersion:"3",minorVersion:"3.4",releaseDate:"2010-04-27",_init:function(){var r=this,o=document,m=navigator,f=m.userAgent,l,e,k,j,h,q;r.isOpera=c.opera


Erg bedankt voor de moeite!
 
Ik begrijp niet precies wat je bedoelt;

ik moet deze code op de plaats zetten van welk stuk code?

PHP:
function redirect($url){
        if (!headers_sent()){
            //print('Location: http://'.$_SERVER['SERVER_NAME'].$url);
            header('Location: http://'.$_SERVER['SERVER_NAME'].$url);
        }else {
            die('Redirect Headers error to send <a href="http://'.$_SERVER['SERVER_NAME'].$url.'" >here the link</a>');
        }
    }

Dit is nog een foutmelding die ik via de toolbar krijg!::

Error: syntax error
Source File: http://*******.nl/cms1/index.php/EDITOR/jscripts/tiny_mce/tiny_mce.js
Line: 1, Column: 72
Source Code:
naar het overzicht</a>]</p><hr width="825px" align="left">(function(c){var a=/^\s*|\s*$/g,d;var b={majorVersion:"3",minorVersion:"3.4",releaseDate:"2010-04-27",_init:function(){var r=this,o=document,m=navigator,f=m.userAgent,l,e,k,j,h,q;r.isOpera=c.opera


Erg bedankt voor de moeite!

de functieblock komt willekeurig te staan bovenaanook goed onderaan ook goed

maar dan zie je +/- regel 50
}else{
unset($_SESSION["login"]);
header("Location: " . $_SERVER['PHP_SELF']);
}
telkens je header("Location
ziet verander je het door redirect("url")
dan komt het de error boodschap als je all een stuk van de header hebt vestuurt omdat de error dan niet duidelijk is om dat uit te sluiten

Kijk toch effe hoe ik je code compacter maakte zodat je de overbodige tags eruit kan smijten ?><? staat erg slordig en totaal overbodig en voor één lijn gebruik je print
 
Oke, code ingevoerd en header location aangepast in:

PHP:
else{
    unset($_SESSION["login"]);
    redirect($url);
  }

Op de site verandert er niets.

Heel erg bedankt voor het opschonen van de code! doch, wanneer ik die gebruik krijg ik een foutmelding, op lijn 203 een unexpected "}" :(

de vorige foutmelding die ik weergaf van de toolbar is er ook nog, het punt van de het grote rode teken is waar de toolbar de fout aangeeft..

heb ik goed gehandeld?

bedankt!
 
mijn fouten zijn er uit
PHP:
<?
session_start();
//One Page CMS - written by Paul Tero 23/1/2009. This simple CMS allows you to edit
//text within HTML and PHP pages which appear between comments that look like:
//<!--ONEPAGECMS-START-LEFT-COLUMN--> and <!--ONEPAGECMS-END-->.
//See http://www.tero.co.uk/scripts/onepagecms.php for more information
//From 7/12/2009 this editor can also handle images!
//Specify which files are allowed to be edited. This accepts wildcards and can be an array, eg:
//$ALLOWEDFILES = array ("home/*.php", "about/*.html");
$ALLOWEDFILES = 'html/*.html';
//Directory where we should save backups every time a file is edited. Leave blank to disable this feature
$BACKUPDIR = 'cmsbackups/';
//Directory where images should be (or are already) stored. Leave blank to disable this feature.
$IMAGEDIR = 'cmsimages/';
//If we want to use the TinyMCE editor, pass in the theme. Can be blank for no editor, simple, or advanced.
//Note that this uses the Javascript files from the TinyMCE server, with some extra code to allow popups
//and inserting images to work.
$HTMLEDITOR = 'advanced'; //leave blank to disable
//Site name
define ("SITETITLE", "Test");
//HR (horizontal line width)
define ("HRWIDTH", "825px");
//Site base url
define ("BASE_URL", "*************.nl/");
////////////////////////////// BEVEILIGING ///////////////////////////////////////////////////
////////////////////////////// edit username & password //////////////////////////////////////
function redirect($url){
	if (!headers_sent()){
			//print('Location: http://'.$_SERVER['SERVER_NAME'].$url);
			header('Location: '.$url);
			die('<meta http-equiv="refresh" content="0;URL="'. $url .'" />');
	}else {
			die('Redirect Headers error to send <a href="'.$url.'" >here the link</a>');
	}
}
$username = "test";
$password = "test";
//////////////////////////////////////////////////////////////////////////////////////////////
if(isset($_GET['logout'])){
  unset($_SESSION["login"]);
  redirect("http://". BASE_URL ."cms/logout/");
  exit;
}
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_SESSION["login"]) || !isset($_SESSION['realm'])) {
  $_SESSION['realm'] = mt_rand( 1, 10000 )." @ ". SITETITLE .
  header("WWW-Authenticate: Basic realm=".$_SESSION['realm']);
  header("HTTP/1.0 401 Unauthorized");
  $_SESSION["login"] = true;
  //echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://". BASE_URL ."cms/logout-wrong/\" />";
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<=====================hier wordt er in gegaan  normaal lijkt me niet 
  redirect("http://". BASE_URL ."cms/logout/");//je moet zoeken naar een print event voor je de header verstuurt
  exit;
}else{
  if($_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password){
    echo "<p><h1>".SITETITLE." - CMS</h1>";
    echo "<p>Je bent ingelogd als: $username [<a href='" . $_SERVER['PHP_SELF'] . "?logout'  class=\"menu\">Logout</a>]";
    echo " OF: Sluit de browser om uit te loggen. [<a href=\"index.php\" target=\"_self\" class=\"menu\">Terug naar het overzicht</a>]</p>";
  }else{
    unset($_SESSION["login"]);
    redirect($_SERVER['PHP_SELF']);
  }
}
echo "<hr width=" .HRWIDTH. " align=\"left\">";
/////////////////////////////// Helpful functions ///////////////////////////////
//This gets all files matching $match. It looks recursively using glob or the find command.
function GetMatchingFiles ($matches) {
    if (!is_array ($matches)) $matches = array ($matches); //the things to match
    $files = array(); //the array of files
    foreach ($matches as $match) {
        //if the glob function exists
        if (function_exists ("glob") && ($globfiles = glob ($match)) && is_array ($globfiles)) $files = array_merge ($files, $globfiles);
        //or else use the find function
        else if (exec ('find . -type f | grep "' . str_replace ('*', '.*', str_replace ('.', '\.', $match)) . '"', $findfiles) && is_array ($findfiles)) $files = array_merge ($files, $findfiles);
        //or else just add the file
        else array_push ($files, $match);
    }
    return $files;
}
 
 
//Get the image files from a directory and its subdirectories
function GetImageFiles ($imagedir) { 
    $imageendings = array ('gif', 'jpg', 'jpeg', 'png');
    $a = array(); foreach ($imageendings as $ending) $a = array_merge ($a, GetMatchingFiles ("$imagedir*.$ending"));
    $images = array(); foreach ($a as $image) $images[$image] = preg_replace ("|^$imagedir|", '', $image); //with and without the directory
    return $images;
}
 
//This gets the editable areas from a file
function GetEditableAreas ($file) {
    $areas = array(); //this is an array of editable areas
    $fc = file_get_contents ($file); //get the file conents
    //Get all the editable areas, s is so that . matches multiline, U is for ungreedy
    preg_match_all ('/<!--ONEPAGECMS-START-([\w\d-]+)-->(.*)<!--ONEPAGECMS-END-->/sU', $fc, $matches, PREG_SET_ORDER);
    //Loop through the matches and put them into an array, also removing any \r characters that might get entered
    foreach ($matches as $m) array_push ($areas, array (ucwords (str_replace ('-', ' ', $m[1])), $m[2]));
    //Return the editable areas which is an array of arrays each with 2 elements for the name and text
    return $areas;
}
 
//For saving a file
function SaveFile ($file, $areas, $backupdir='') {
    //First check we can save the data
    if (!$areas) return "Er is geen data om op te slaan!";
    $fc = file_get_contents ($file); //get the file conents
    if (!$fc) return "Kan het bestand: $file niet lezen";
    //Now get allthe parts with tags
    $parts = preg_split ('/(<!--ONEPAGECMS-[\w\d-]+-->)/', $fc, -1, PREG_SPLIT_DELIM_CAPTURE); //split by the ONEPAGECMS tags
    if (count ($parts) != count ($areas) * 4 + 1) return "Er zijn een verkeerd aantal ONEPAGECMS tags in het bestand";
    $newcontents = array_shift ($parts); //get the first bit before the first ONEPAGECMS tag
    //For each editable area, get the START tag, the editable area, the end tag, then the part after the END tag
    foreach ($areas as $i=>$area) //remove slashes and \r from the data being saved
        $newcontents .= $parts[$i*4] . "\n" . trim (stripSlashes (preg_replace ("/\r\n?/", "\n", $areas[$i]))) . "\n" .
            $parts[$i*4 + 2] . $parts[$i*4+3];
    //Backup the file before saving it, and make the backup world writeable so it can be deleted via FTP
    if ($backupdir) {
        if (!is_dir ($backupdir)) {mkdir ($backupdir); chmod ($backupdir, 0777);}
        copy ($file, $backupfile = $backupdir . '/' . str_replace ('/', '-', $file) . '.' . date ('Y-m-d-Hi') . '.backup');
        if (file_exists ($backupfile)) chmod ($backupfile, 0666);
    }
    //Save the contents
    $fw = fopen ($file, 'w'); //try to open the file for writing
    if (!$fw) return "Kan de gewijzigde data in het bestand $file niet wegschrijven. Check of er voldoende rechten zijn.";
    //Save the file
    fwrite ($fw, $newcontents); fclose ($fw);
    return "Bestand is succesvol opgeslagen.";
}
//Saving the images
function SaveImages ($imagedir) {
    $imageendings = array ('gif', 'jpg', 'jpeg', 'png'); $m = array();
    if (!is_dir ($imagedir)) {mkdir ($imagedir); chmod ($imagedir, 0777);}
    //Check it's the right endings, etc
    if (isset ($_POST['remove'])) foreach ($_POST['remove'] as $image) 
        if (preg_match ("~^$imagedir.+\." . join ('|', $imageendings) . '$~', $image)) {$m[] = "Bezig $image te verwijderen"; unlink ($image);}
        else $m[] = "Kan $image niet verwijderen (misschien door de bestandsextensie)";
    foreach ($_FILES as $formfield=>$filedata) {
        if (!$filedata['size']) continue; //nothing to upload
        $moveto = $imagedir . $filedata['name'];
        if ($filedata['error']) $m[] = "Kan $filedata[name] niet uploaden omdat: $filedata[error]";
        else if (!preg_match ('~\.' . join ('|', $imageendings) . '$~', $filedata['name'])) $m[] = "Kan $filedata[name] niet uploaden. (Verkeerde bestandsextensie)";
        else {$m[] = "Saving $moveto"; move_uploaded_file ($filedata['tmp_name'], $moveto); chmod ($moveto, 0666);}
    }
    return join ('<br/>', $m);
}
/////////////////////////////// Advanced editor ///////////////////////////////
//This code helps make the advanced TinyMCE editor work. When using the advanced editor, all files required from the editor
//are passed through onepagecms.php first. This means they will all appear to be coming from the local domain and avoids
//Javascript security alerts and problems. It also means that I can hack the image inserter so that it shows a drop down
//list of images from $IMAGEDIR.
function ProcessEditor ($imagedir) {
    if (!preg_match ('|EDITOR/(.*)$|', $_SERVER['REQUEST_URI'], $ed)) return;
    if (preg_match ('/css$/', $ed[1])) header ("Content-type: text/css"); //output the mime type header for CSS files
    //If this has been requested before (or it's image.htm), then just return the Cached version
    if (basename ($ed[1]) != 'image.htm' && isset ($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { //it's been requested before
        header ("Expires: Sat, 6 Mar 1976 10:00:00 GMT"); //expire the page at some time in the past
        header ("Cache-Control: private, must-revalidate"); //let them cache it
        header ("Pragma: cache"); //override the default header to reallow caching
        header ("HTTP/1.0 304 Not Modified");
        exit;
    }
    //Or else get the file contents over the Internet and return them
    $contents = file_get_contents ('http://tinymce.moxiecode.com/js/tinymce/' . rawurldecode ($ed[1])); //get the contents of the file
    if (basename ($ed[1]) == 'image.htm' && ($idpos = strpos ($contents, 'id="src"'))) { //this is the image uploading HTML file
        $select = '<tr><td><label for="image_list2">Or choose from</label></td><td><select id="image_list2" name="image_list2" onchange="document.getElementById(\'src\').value=this.options[this.selectedIndex].value;"><option value="">choose one</option>';
        $images = GetImageFiles ($imagedir); //the images to put in the drop down
        foreach ($images as $src=>$image) $select .= '<option value="' . $src. '">' . $image . '</option>';
        $select .= '</select></td></tr>';
        $trpos = strpos ($contents, '<tr>', $idpos);
        if ($images && $trpos) $contents = substr ($contents, 0, $trpos) . $select . substr ($contents, $trpos);
    } else header ("Last-Modified: " . gmdate ("D, d M Y H:i:s")); //send now as the last modified date
    echo $contents; 
    exit;
}
ProcessEditor ($IMAGEDIR); 
/////////////////////////////// Outputting the page ///////////////////////////////
function OutputPage ($allowedfiles, $backupdir='', $htmleditor='', $imagedir='') {
    $me = $_SERVER['SCRIPT_NAME']; //my page nmae
    $areawidth = 100; //the width in columns of the text area
    $filestoedit = GetMatchingFiles ($allowedfiles); //files I am allowed to edit
    $imagemanager = isset ($_GET['imagemanager']) ? $_GET['imagemanager'] : ''; //should we show the image manager
    $editfile = isset ($_GET['file']) ? $_GET['file'] : ''; //the file they want to edit
    if (!in_array ($editfile, $filestoedit)) $editfile = ''; //the file must be in the array of allowed files
    $editareas = $editfile ? GetEditableAreas ($editfile) : array(); //the areas to edit
    $saveimages = isset ($_POST['imagemanager']) ? $_POST['imagemanager'] : ''; //if there are images to save
    if ($saveimages) $imagemanager = true; //we should view the image manager if saving images
    $savefile = isset ($_POST['file']) ? $_POST['file'] : ''; //if there is a file to save
    if (!in_array ($savefile, $filestoedit)) $savefile = ''; //the file must be in the array of allowed files
    $saveareas = $savefile && isset ($_POST['areas']) ? $_POST['areas'] : array(); //areas of the page to save
?>
<html>
<head>
<style type="text/css">
<!--
@import url("http://<?PHP echo BASE_URL ?>cms/scripts/style.css");
-->
</style>

<title><?PHP echo SITETITLE ?> - CMS</title>
<? if ($htmleditor) {$editorprefix = $htmleditor=='advanced' ? "$me/EDITOR/" : 'http://tinymce.moxiecode.com/js/tinymce/'; //for the HTML editor ?>
<script type="text/javascript" src="<?=$editorprefix?>jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">tinyMCE.init({mode : 'textareas', theme : '<?=$htmleditor?>'});</script>
<? } ?>
</head>
<body>
<h2>Beheer html</h2>
<p>
Hieronder staat een overzicht van de pagina s waarop velden staan die je kan aanpassen.<br />
</p>
<ul>
<?  foreach ($filestoedit as $listfile) if (basename ($me) != basename ($listfile)) { ?>
<li><a href="<?=$me?>?file=<?=$listfile?>"><?=$listfile?></a> (<a href="<?=$listfile?>">Bekijk</a>)</li>
<?  } 
  if ($imagedir) { print"<li><a href='".$me."?imagemanager=yes'>Beheer images</a></li>"; } //a link to the image manager ?>
</ul><br />
<? /** /////////////////////////////////////////////////////////////////AUDIO///////////////////////////////////////////*/?>
<hr width="<? echo HRWIDTH ?>" align="left">
<h2>Beheer audio</h2>
<p>Hieronder kan een mp3 bestand geselecteerd worden om te uploaden, max 10mb.<br /><br /></p>
<?
echo "<form method='post' enctype='multipart/form-data'><input type='file' name='file' width='300px'>&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='upload1' value='Upload'> </form>";
$map = "audio/";  //map waar die in komt (wel chmod permision 777 geven 
if(isset($_POST['upload1'])) { 
  if($_FILES['file']['size'] <= 1024*10000) {  
    // Controle of het bestand groter is als 10 mb (tussen de [''] van $_FILES vul je de naam van het veld in) 
    $extension = array(); 
    $extension[] = "audio/mp3";  // zet de extensions (vb: .jpg) in de array..  
    $extension[] = "audio/mpeg";  // altijd met audio/ ervoor en zonder punt 
    // Let op .jpg kan hij verschillend zien (bv: ook als .pjpg) zoek dus op internet een lijst anders krijg je vaak errors.. 
    if(in_array($_FILES['file']['type'], $extension)) { 
    // Controle of hij een bestand met de juiste extension heeft geupload 
      if(is_uploaded_file($_FILES['file']['tmp_name'])) {  //Contorleren of hij is geupload 
        move_uploaded_file($_FILES['file']['tmp_name'], $map.$_FILES['file']['name']); 
        // eerst geef je de file aan met de tmp naam waar die tijdelijk staat op geslagen, daarna de mapnaam en de filenaam met een punt er tussen  
        echo "<p><span style=\"color:#F00\">Bestand succesvol geupload..</span></p>"; 
      } else { 
        echo "<p><span style=\"color:#F00\">Er is iets mis gegaan bij het uploaden, probeer het nogmaals</span></p>"; 
      } 
    } else { 
      echo "<p><span style=\"color:#F00\">Het bestand heeft een verkeerde extensie</span></p>"; 
    } 
  } else { 
    echo "<p><span style=\"color:#F00\">Het bestand moet kleiner zijn dan 10 mb</span></p>"; 
  } 
} else { 
// Hier je formulier (deze is zichtbaar wanneer er niet op submit is gedrukt..) 
} 


if ($savefile) { //there is a file to save ?>
<hr width="<? echo HRWIDTH ?>" align="left">
<h2>Wijzigingen opslaan in: <span style="color:#F00"><?=$savefile?></span><br /><br /></h2>
<p>Bezig het volgende bestand op te te slaan: <a href="<?=$me?>?file=<?=$savefile?>"><?=$savefile?></a>
(<a href="<?=$savefile?>">bekijk</a>). Mogelijke foutmeldingen tijdens het opslaan verschijnen hier... <br /><br /></p>
<p><b><?= SaveFile ($savefile, $saveareas, $backupdir) ?></b></p>
<?  } //file to save 
  if ($editfile) { //there is a file to edit ?>
<br /><br /><hr width="<? echo HRWIDTH ?>" align="left">
<h2>Wijzig het bestand <span style="color:#F00"><?= $editfile?></span></h2>
<p>Wijzig <?=$htmleditor ? 'tekst' : 'HTML'?> in de velden hieronder en sla de wijzigingen dan op!<br /><br />
<div style="width:550px; height:80px; background-color:#F6F6F6; border-style:dashed; border-width:thin; margin-left:150px; padding:3px;">
  <p><b>Om een nummer op de site te plaatsen moet er eerst op -html- worden gedrukt.</b> Dan moet deze code gecopieerd en geplakt worden:<br />
  &lt;p&gt;&lt;a href=&quot;audio/***.mp3&quot;&gt;***&lt;/a&gt;&lt;/p&gt;<br /><br />Op de plek van de *** moet de bestandsnaam worden geplaatst.<br /><br /></p></div>
<form method="post" action="<?=$me?>">
<input name="file" type="hidden" value="<?=$editfile?>" />
<? /** */   if (!$editareas) echo "<p><b>Sorry, maar $editfile heeft geen aan te passen velden.</b></p>"; 
	      	foreach ($editareas as $area) {
				$numlines = $htmleditor ? 20 : substr_count (wordwrap ($area[1], $areawidth), "\n"); 
		      	print"<h3>".$area[0]."</h3>";
			  	print"<textarea name='areas[]' rows='".max($numlines, 5)."' cols='".$areawidth."'>".$area[1]."</textarea>";
			}
      echo "<br /><br /><hr width='".HRWIDTH."' align='left' />";
      if ($editareas) echo '<p><input type="submit" value="Save"/></p><br /><br /><br />'; 
			  print'</form>';
      } //file to edit 
      if ($saveimages) { //saving the images
		?>
		<h2>Saving images</h2>
		<p>Saving de images. Mogelijke foutmeldingen tijdens het opslaan verschijnen hier...</p>
		<p><b><?= SaveImages ($imagedir) ?></b></p>
		<?
	  }
	  if ($imagemanager) { //they want to manage iamges ?>
		<br /><br /><hr width="<?PHP echo HRWIDTH ?>" align="left" />
		<h2>Beheer images</h2>
		<p>Gebruik de onderstaande links om images te bekijken, verwijderen en uploaden naar: <?=$imagedir?>.</p>
		<form method="post" action="<?=$me?>" enctype="multipart/form-data">
		<input name="imagemanager" type="hidden" value="yes" />
		<ul>
		<?  foreach (GetImageFiles ($imagedir) as $src=>$image) {
        print"<li><p><a href='$src' target='onepagecms_view'>$image</a>(<input type='checkbox' name='remove[]' value='".$src."'>verwijderen?)</p></li>";
	   } ?>
	<li>Upload een nieuw image: <input type="file" name="newimage1" size="20" /></li>
</ul>
<br /><br />
	<hr width="<? echo HRWIDTH ?>" align="left" />
	<input type="submit" value="Save"/>
	<br /><br /><br />
</form>
<?  }
print" </body></html>";  
} //finish the output page function
/////////////////////////////// Run the CMS ///////////////////////////////
//Turn on error reporting so the user can see everything like file writing errors
ini_set ('display_errors', 1);
error_reporting (E_ALL);//!!!security!!! //TODO @todo remove before upload
//Output the page
OutputPage($ALLOWEDFILES, $BACKUPDIR, $HTMLEDITOR, $IMAGEDIR);
?>
</body>
</html>
 
Laatst bewerkt:
pffffff het was inderdaad een header probleem.

heb de beveiligingscode helemaal naar onderen verplaatst, net boven het begin van de html en het werkt perfect!

iig bedankt voor de moeite, blij dat ik er na een week uit ben!
 
pffffff het was inderdaad een header probleem.

heb de beveiligingscode helemaal naar onderen verplaatst, net boven het begin van de html en het werkt perfect!

iig bedankt voor de moeite, blij dat ik er na een week uit ben!

lees vooral lijn 305 van het laatste script
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan