Jump to content

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'] .\")\";
}
");

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.