Jump to content

stops echo, when it shouldn't..


Sesquipedalian

Recommended Posts

I'm posting php to a file, and for some reason right before [Delete Bulletin] it seems to think that I ended the echo I was doing.. when I didn't... whats wrong? I tried multiple different arrangements and uses of the quotes... =/

 

$content = '<? if ($_SESSION["lvl"] == "1")'. " { echo '<a".' href="?login=deletebulletin&bulletin=$date">'."[Delete Bulletin]</a>'; } ?>";

Link to comment
Share on other sites

<?php

$content = '<?php if ($_SESSION["lvl"] == "1") { echo "<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>"; } ?>';

?>

 

what is the use of <?php  ???

 

It defines the start of a block of php code.

Link to comment
Share on other sites

yes but take a look carefully

 

$content =

  is a variable  so i supposed you are inside php block and your php tags in that code will be treated as string please let me know if i was wrong

 

is this i typo error or this is really valid?

Link to comment
Share on other sites

The op wants them to be treated as a string. Read the question. I think the op wants to write php code to a file. eg;

 

<?php

  $contents = "<?php echo 'this is some php'; ?>";
  file_put_contents('newfile.php',$contents);

?>

Link to comment
Share on other sites

can you tell me the expected output for that? maybe your right sorry!

 

but the output of that code wont give you what you're expecting try it it html tags has been used < unexpectedly because <?php is treated as string to display try it!

Link to comment
Share on other sites

use html entities.. your string is treated as html tags because of unwanted use of <

$content = '<?php if ($_SESSION["lvl"] == "1") { echo "<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>"; } ?>';
echo htmlentities($content);

Link to comment
Share on other sites

use html entities.. your string is treated as html tags because of unwanted use of <

$content = '<?php if ($_SESSION["lvl"] == "1") { echo "<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>"; } ?>';
echo htmlentities($content);

 

No you see I want it to display the link but somehow it gets broken and just displays what I wrote before as text.

Link to comment
Share on other sites

Oh sorry, I didn't have session_start();

I made the encryption a little less, and it still does it, so Ill try to show more code for you guys..

 

It was working, but when I put it so it will post to the file, it does what my problem at first was. This is the code for when it posts ($content is the content submitted from the form).

$newcontent = str_replace('<?', '', str_replace('?>', '', $content));
$delete = ($_SESSION["lvl"] == "1")?"<a href=\"?login=deletebulletin&bulletin=$date\">[Delete Bulletin]</a>":'';
$filename = 'bulletin.txt';
putenv("TZ=America/Denver");
$date = date("D dS M, Y h:i:s a");
$final_en = base64_encode('<b><i>'.$date.'</i></b><br />'.$newcontent.' '
	.'<i>-'.$_SESSION['user'].'</i><br />'
	."<?php echo $delete; ?>");
$somecontent = ' | '.$final_en;
chmod ($filename, 0777);
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
	 echo "Cannot open file.";
		 exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
	echo "Cannot write to file.";
		exit;
}

fclose($handle);
echo '<h1>Bulletin Posted </h1><center><a href="index.php">Your bulletin has been posted.</a></center><br /><br />'
.'<META HTTP-EQUIV=Refresh CONTENT="1; URL=index.php">';
include ('links.php');
} else {
echo "The file is not writable";
}

 

And then this is when I display the file...

$file = 'bulletin.txt';
echo '<b>Welcome, you are currently logged in as: </b>'.$_SESSION['user'].'.<br />'
.'<b>User level: </b>'.$_SESSION['lvl'].'.<br /><br />';
if (filesize($file) !== 0) {
echo '<h1>Bulletins</h1>';
$filename = 'bulletin.txt';
$handle = fopen($filename, 'r');
$read = fread($handle, filesize($filename));
$array = explode(' | ', $read);
$i = 0;
while ($array[$i] !== NULL) {
	echo base64_decode($array[$i]);
	$i++;
}
if ($_SESSION['lvl'] == '1') {
	echo '________________<br />'
		.'<a href="?login=deletebulletins">Delete All Bulletins</a><br /><br />';
}
}

 

I think that I could probably just put that part into when I display the files, but it was working before, and it seemed easier. Should I do that, or is there a way to make it actually work..?

 

Link to comment
Share on other sites

Well, if I write that exact string to a file. eg;

 

<?php

  $date = date("D dS M, Y h:i:s a");
  $content = '<?php if ($_SESSION["lvl"] == "1") {echo "<a href=\"?login=deletebulletin&bulletin=' . $date . '\">[Delete Bulletin]</a>"; ?>';
  file_put_contents('file.php',$content);

?>

 

It writes perfectly fine.

Link to comment
Share on other sites

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.