Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:54:45+00:00 2026-05-16T17:54:45+00:00

<?php eval(if (1==1){); echo (‘abc’); eval(}); ?> Then i get a error : Parse

  • 0
<?php
eval("if (1==1){");
echo ('abc');
eval("}");
?>

Then i get a error :
Parse error: parse error in C:\wamp\www\test\index.php(2) : eval()’d code on line 1
abc
Parse error: parse error in C:\wamp\www\test\index.php(4) : eval()’d code on line 1
How to fix?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:54:46+00:00Added an answer on May 16, 2026 at 5:54 pm

    You should really try to avoid using eval if at all possible. It presents an enormous and nearly unsurmountable security risk. I have never in my career come across a good reason to use this function. If you post an example, maybe we can help you find a way to accomplish your goal without this immense risk.

    Disclaimer aside, I think the issue is that you’re starting an expression in the eval that needs to be complete.

    You could try this instead:

    <?php
        $test = eval("return 1==1;");
    
        if($test)
        {
             echo 'abc';
        }
    

    edit:

    The goal is to do something like this:

    [if {expression}][blog_title][endif]
    

    Here is an idea. Instead of allowing the user to enter any expression, just use a variable, which the user can set. For example:

    [if should_show_blog_title][blog_title][endif]
    

    Then, the user could do this (pseudo-ish code, since I’m not sure what your templating API looks like):

    $template = new Template();
    
    // shows blog title
    $template->set_variable('should_show_blog_title', 1 == 1); // 1 == 1  is true, so the variable is true
    $template->set_variable('blog_title', 'Awesomesauce Blog!');
    
    // doesn't show title
    $template->set_variable('should_show_blog_title', 1 == 0); // 1 == 0 is false, so the variable is false
    $template->set_variable('blog_title', 'Awesomesauce Blog!');
    

    Another idea would be to provide a limited number of operators or functions that the user could use. Instead of evaling it, you have to parse it. For example:

    [if not_empty(blog_title)][blog_title][end if]
    

    Then when you parse and compile the template (insert the data in, basically), you look for these special functions and translate them in to PHP. This is basically whitelisting, since you’re only letting the user perform a very restricted subset of functionality.

    You should look at Mustache, which kind of follows the first idea. The implementation is actually pretty simple. The PHP implementation of mustache is here: mustache.php. You could look through the samples and some code to see if you could get some ideas.

    One thing to keep in mind, is that if you’re evaling, the templating engine isn’t going to be as user-friendly, because then the user has to write valid PHP in their conditions. Part of the appeal of mustache is that it’s so simple and incredibly easy to use. I’m an experienced PHP developer, and while I can hack in PHP all day long, I still prefer mustache for templating because it just lets me get to the point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PHP code: echo date(c); //out put like this 2012-06-19T20:37:44+05:30 echo date(d M, Y); //out
I have a eval function like this if(FALSE === @eval($code)) echo 'your code has
I want to store php code inside my database and then use it into
Let's say file test.php looks like this: <?php echo 'Hello world.'; ?> I want
please see the code below : <?php $str = 'PD9waHANCiRzdHJpbmcgPSAiYmVhdXRpZnVsIjsNCiR0aW1lID0gIndpbnRlciI7DQoNCiRzdHIg PSAnVGhpcyBpcyBhICRzdHJpbmcgJHRpbWUgbW9ybmluZyEnOw0KZWNobyAkc3RyLiAiPGJyIC8+ IjsNCg0KZXZhbCgiXCRzdHIgPSBcIiRzdHJcIjsiKTsNCmVjaG8gJHN0cjsNCj8+IA=='; echo base64_decode($str);
I am facing a strange problem. My PHP page has following code. echo <div
<?php $xs = eval(if ('1' == '0') echo 'never'; else echo 'always';); //echo $xs;
I'm wondering what sorts of things should be checked when using eval() in PHP
Possible Duplicate: Dirt-simple PHP templates… can this work without eval ? Let's say I
Does a method like eval exist in Objective-C as in Javascript, Ruby, PHP, or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.