vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Trouble using eval() (https://vborg.vbsupport.ru/showthread.php?t=135828)

thincom2000 01-07-2007 11:37 PM

Trouble using eval()
 
I am trying to write a script that uses eval() to parse vBulletin variables and phrases from a string. However, I get a parse error if the string contains a colon : and probably if I tried a semicolon ; as well.

Is there a way to escape the colons with a function such as addslashes()?

How do I get around this?

nico_swd 01-08-2007 11:06 AM

They don't need to be escaped. Can you post your code?

thincom2000 01-15-2007 03:02 AM

Okay I got around escaping the colons. But here's what I'm trying to do:

The user enters a string containing a list of variables in an input field. These variables then need to be interpreted as globals, but the following oh so simple code won't work:

PHP Code:

global eval('return $user_entered_globals;'); 

:confused:

EDIT: Never mind. Although this would be nice to know for the future, I decided against user-entered globals this time around.

harmor19 01-15-2007 06:26 AM

Wouldn't you use

PHP Code:

<?php

$user_entered_globals 
= array("test1""test2""test3");

if(!
in_array($_GET['test'], $user_entered_globals))
{
   die(
"Error!");
}

function 
something()
{

global 
$user_entered_globals;

eval(
'$user_entered_globals');

}

?>

This code is untested

thincom2000 01-16-2007 02:36 AM

Got it working.

PHP Code:

$test1 'string';
$test2 = Array('string1''string2');
$test3 some_class;

$user_entered_globals '$test1, $test2, $test3';

eval(
'global ' $user_entered_globals ';'); 

This is very simplified, but working. :rolleyes:


All times are GMT. The time now is 10:17 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01108 seconds
  • Memory Usage 1,720KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete