Jump to content

eval()


yoshida

Recommended Posts

EDIT: stupid me. There was a syntax error in my script.I now have access to base html content for my script editor. Get this: within days I can throw my default script editor out of the window and replace it with easyphp and my own html-based editor.Hi. I want to learn about eval().Here's what I want:

$query="SELECT * FROM standaard WHERE name='css'";$result=mysql_query($query);$num=mysql_num_rows($result);$i=0;while($i < $num) {	$content=mysql_result($result,$i,"content");	echo stripslashes($content);	$i++;}// When logged on, this is where the webmaster menu is loaded;if ($_SESSION['logid'] == '1') {	$query="SELECT * FROM standaard WHERE name='bram'";	$result=mysql_query($query);	$num=mysql_num_rows($result);		$i=0;	while($i < $num) {		$content=mysql_result($result,$i,"content");		echo stripslashes($content);		$i++;	}}// this is where the head is loaded. The head is editable from the webmaster menu;$query="SELECT * FROM standaard WHERE name='head'";$result=mysql_query($query);$num=mysql_num_rows($result);$i=0;while($i < $num) {	$content=mysql_result($result,$i,"content");	echo stripslashes($content);	$i++;}

The purpose is to create a script manager, to manage a script library. The library will be used by a number of websites, and replaces most of the scripts used by those sites.Does anyone have a way of doing this? Or am I overlooking something? Help appreciated.

Link to comment
Share on other sites

Eval will work fine for what you want to do. You can think of eval as essentially replacing the eval line with the code in the variable. But I bet you're seeing some abnormal behavior with this. If you replace the code yourself to see what is being executed, you can see why:

$query="SELECT * FROM scripts WHERE sid='basecontent'";$result=mysql_query($query);$num=mysql_num_rows($result);$i=0;while ($i < $num) {	//replace eval with the code$query="SELECT * FROM standaard WHERE name='css'";$result=mysql_query($query);$num=mysql_num_rows($result);$i=0;while($i < $num) {	$content=mysql_result($result,$i,"content");	echo stripslashes($content);	$i++;}// When logged on, this is where the webmaster menu is loaded;if ($_SESSION['logid'] == '1') {	$query="SELECT * FROM standaard WHERE name='bram'";	$result=mysql_query($query);	$num=mysql_num_rows($result);		$i=0;	while($i < $num) {		$content=mysql_result($result,$i,"content");		echo stripslashes($content);		$i++;	}}// this is where the head is loaded. The head is editable from the webmaster menu;$query="SELECT * FROM standaard WHERE name='head'";$result=mysql_query($query);$num=mysql_num_rows($result);$i=0;while($i < $num) {	$content=mysql_result($result,$i,"content");	echo stripslashes($content);	$i++;}	}

The problem is that the variables in the eval'd code have the same names as the variables in the rest of the code, and are creating confusion. In order to guarantee this working, name the rest of the variables (in the code that does the eval) something unique that would never be in someone else's script.

Link to comment
Share on other sites

True, so I'll have to keep an eye on that. Last thing I knew was that the last parsed value of a variable is always true.Thanks.PS for the rest of the site 'basecontent' will be replaced by a propagated variable (WHERE sid='$_GET['pageid']')

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...