Jump to content

I DONT UNDERSTAND "EVAL()" WTFFF


Jarod

Recommended Posts

How do I use eval()? Man it's so confusing, I thought I had it at first. It work, but not until I really needed... I used it with a function and it's not doing so!

 

	// set_session("username", "user1");
function set_session($session, $username) {
	eval($_SESSION['$session'] = $_POST['$username']);
}

Link to comment
https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/
Share on other sites

How do I use eval()? Man it's so confusing, I thought I had it at first. It work, but not until I really needed... I used it with a function and it's not doing so!

 

	// set_session("username", "user1");
function set_session($session, $username) {
	eval($_SESSION['$session'] = $_POST['$username']);
}

 

Maybe you should look at the eval function and read what it actually does.

OK wut did I do wrong in this???

 

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\practices\test\index.php on line 1

 

eval("
if( !isset($_SESSION['server']) ) {
$_SESSION['server'] = \"Direct TV\";

echo $_SESSION['server']; 
} else {
echo \"<b>Server</b> already set! (\".  $_SESSION['server'] .\")\";
}
");

OK wut did I do wrong in this???

 

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\practices\test\index.php on line 1

 

eval("

if( !isset($_SESSION['server']) ) {

  $_SESSION['server'] = \"Direct TV\";

 

  echo $_SESSION['server'];

} else {

  echo \"<b>Server</b> already set! (\".  $_SESSION['server'] .\")\";

}

");

$ needs to be escaped inside of double quotes:

 

eval("if( !isset(\$_SESSION['server']) ) { 
    \$_SESSION['server'] = \"Direct TV\";
   
   echo \$_SESSION['server'];
} else {
   echo \"<b>Server</b> already set! (\".  \$_SESSION['server'] .\")\";
}
");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.