okay so i got a little script that from button links load different information within the same page what im trying to achieve is pulling php coding to the same file but each time i try it throws up errors

below is the code that is giving me a problem (its a banip script)

$getpage['code'] = '<p>

<center>
{

if($_POST['Submit']){ 
$open = fopen("ipban.php","w+"); 
$text = $_POST['update']; 
fwrite($open, $text); 
fclose($open);
}  
echo "</textarea>"; 

$file = file("ipban.php"); 
echo "<center><br />Please enter the IP Address you wish to ban, One IP Address per line and click update.<br /><br /><form action=\"".$PHP_SELF."\" method=\"post\">"; 
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">"; 
foreach($file as $text) { 
echo $text;
}
echo "</textarea><br />"; 
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n 
</form>"; 

}

I think it might be this:

'<p>
 
<center>
{
 
if($_POST['Submit']){

php thinks the first ' of the $_POST is the closing ' from = '<p>
I do though not see what could be the closing ' for the $getpage

I think you forgot to do $getpage='<p>'

I think it might be this:

'<p>
 
<center>
{
 
if($_POST['Submit']){

php thinks the first ' of the $_POST is the closing ' from = '<p>
I do though not see what could be the closing ' for the $getpage

I think you forgot to do $getpage='<p>'

The closing is there on the next line below which i didnt add in but will try keep trying

There seem to be more than one problems with that code.
there are <center> tags with no </center>, there is probably more serious issues as well.

I agree that there is some thing wrong at the start.
If that code is meant to be stuffed into an associative array cell called code, then there should be a closing single quote after the bracket on line 24.

what im trying to do is get it parse the PHP code below the $getpage so i left it open there and close it further down but that obviously doesnt work is there another way around this. i thought about using the include but that just gives me the same error.

What you're trying to do is not possible. There is no way to store PHP code in variables.

I would suggest putting the separate

code snippets that you are trying to store in variables and store them into separate PHP files. Store the names of those files in the array, and then include them.

<?php
 $files = array('one' => 'includes/fileOne.php', 'two' => 'includes/fileTwo.php', 'three' => 'includes/fileThree.php');
 include($files['one']);
?>

Which would actually include the file 'include/fileOne.php'.

what im trying to do is get it parse the PHP code below the $getpage so i left it open there and close it further down but that obviously doesnt work is there another way around this. i thought about using the include but that just gives me the same error.

use double quotes;

$getpage['code'] = " //all code to be parsed here"

Then in the form, you echo the code inside existing php tags?

echo $getpage['code'] ;

The Code below is where all my PHP coding is and on index i just call it using an array which follows further down

$getpage['code'] = '<p>
{
if($_POST['Submit']){ 
$open = fopen("ipban.php","w+"); 
$text = $_POST['update']; 
fwrite($open, $text); 
fclose($open);
}  
echo "</textarea>"; 

$file = file("ipban.php"); 
echo "<center><br />Please enter the IP Address you wish to ban, One IP Address per line and click update.<br /><br /><form action=\"".$PHP_SELF."\" method=\"post\">"; 
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">"; 
foreach($file as $text) { 
echo $text;
}
echo "</textarea><br />"; 
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n"; 
echo "</form>"; 

}';

index.php array

<?php

$title = 'Administration Panel';

$product = array();

if (isset($_GET['page'])) {
	$slashes = array('\\','/');
	$page = str_replace($slashes, '', $_GET['page']);
	if (file_exists('admin/pages/'.$page.'.prod')) {
		include('admin/pages/'.$page.'.prod');
	}
}
else {
	include('admin/pages/admin.page');
	$page = 'Administration ';
}
?>
	<div id="head">
		<h1>Sphyx Design - <?php echo $title; ?></h1>
		<a href="admin.php?page=page1"<?php if ($page == 'page1') { echo ' class="tab active"'; } else { echo ' class="tab normal"'; } ?>><img src="images/admin/banip.png"></a>
		<a href="admin.php?page=page2"<?php if ($page == 'page2') { echo ' class="tab active"'; } else { echo ' class="tab normal"'; } ?>><img src="images/admin/news.png"></a>
		<a href="admin.php?page=page3"<?php if ($page == 'page3') { echo ' class="tab active"'; } else { echo ' class="tab normal"'; } ?>><img src="images/admin/users.png"></a>
		<a href="admin.php?page=page4"<?php if ($page == 'page4') { echo ' class="tab active"'; } else { echo ' class="tab normal"'; } ?>><img src="images/admin/blank.png"></a>
		<a href="admin.php?page=page5"<?php if ($page == 'page5') { echo ' class="tab active"'; } else { echo ' class="tab normal"'; } ?>><img src="images/admin/blank.png"></a>
		<a href="admin.php?page=page6"<?php if ($page == 'page6') { echo ' class="tab active"'; } else { echo ' class="tab normal"'; } ?>><img src="images/admin/blank.png"></a>
	</div>

Sorry, but I have no idea how that is supposed to work.
$getpage is an associative array cell. I don't see where you are using it anywhere other than in the first script where it is loaded with the string.

I'll just state again, for clarity, that it can't be done. It would be a major security issue if you could. There are very very few things I say can't be done in PHP, but this is one of them.

I see what you mean, Someone could drop a "script bomb" on a site.
It is. however, possible to echo out HTML . I do that stuff in loops all of the time.

Of course, storing Javascript or HTML is not a problem.

Member Avatar for diafol

THis is one of the worst examples of php-derived html output I've seen. Sorry no offence meant. Start again.

I think we scared the OP away. He/she has not responded in a while.

got any ideas then and no offence taken im new to php learning as i go along. i got everything else sorted and works fine except for this one part its for a administration page.

If this is something you want to display initially as the result of a previously set condition,then PHP can be used. If the condition is unknown before the page is displayed and you want to display something without a submit, then Javascript might be a better option.

However, the down side to Javascript is that not everybody enables it.
Stay with a PHP solution, if possible.

Functionality shouldn't be dependent on JavaScript (in most cases). These days, I usually don't write complicated applications without JavaScript, and I don't waste time making it work without it. However, for websites, I always make sure things will work without it.

I'm still having a problem figuring out what you're trying to do, though. Other than trying to put PHP in a variable, not sure what else you need. :P

Has i stated earlier im trying to create a admin page using a Array and call function but ive now found out its not gonna work as i thought without having alot of security issues. is there a way that i can create a admin.php file where it stores all administration options and i can just call what is need for instances admin.php?=banip (showing only options for the IP Ban)

i know its been a while but im still looking on how to get a administration page up and running that will show a certain section i.e admin.php?=index showing links and admin.php?=banip show the banip section of the administration page.

any ideas i tried storing the code in different php files and calling them it works fine but wont let me do what i want from it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.