Azu Posted April 5, 2007 Share Posted April 5, 2007 There is a clientside eval function in javascript. Please tell me how I can use something like this serverside in PHP, I would really appreciate it! ^^ Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/ Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 If you would look in the manual you would find that there is eval() for PHP also. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-222496 Share on other sites More sharing options...
Azu Posted April 5, 2007 Author Share Posted April 5, 2007 Thanks, I already tried that though, and it doesn't work for what I am trying to do. I want one that works like the javascript eval, except that it will be ran serverside instead of on the client's computer. I don't want it to run PHP commands. I want a PHP command that runs it, like it would in javascript but on my server instead. Is there something that does this? Or will I have to spend a long time studying javascript and create my own function to do this? And I did read the manual BTW and I searched a long time for this I haven't found it though =( thanks anyways Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-222502 Share on other sites More sharing options...
roopurt18 Posted April 5, 2007 Share Posted April 5, 2007 Are you trying to say you want to execute shell commands with a PHP script? Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-222512 Share on other sites More sharing options...
Azu Posted April 5, 2007 Author Share Posted April 5, 2007 I just want to eval the javascript on server side so that the result is outputted into PHP and can be used by my server, instead of outputted into the client.. please? I think exec() is for running shell commands that isn't what I am looking for though sorry :s Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-222515 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 Javascript does not run on the server, it runs on the client. What are you trying to do? Your explanation doesn't make any sense. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-222516 Share on other sites More sharing options...
Azu Posted April 5, 2007 Author Share Posted April 5, 2007 I have a variable with javascript code in it and when it is ran as javascript on the clientside with eval it changes. I am trying to get it to change the same way on the serverside, and then be able to use that variable. Sorry if I didn't explain it right x_x Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-222517 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 Can you post some example code? Please put you code inbetween tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-222532 Share on other sites More sharing options...
Guest Posted April 5, 2007 Share Posted April 5, 2007 Hi Azu, I believe I understand what you are doing. You want a value FROM javascript to be placed into your PHP so that PHP can work with it. If i'm wrong, please correct me. I remember thinking I could do that when I first started PHP. However, this is unfortunately not possible (a direct link between javascript and PHP) because javascript runs on the clientside (the browser/user's computer) and PHP is processed on the server side. The only remote way I could think about doing this is to use AJAX, and/or perhaps PHP's output buffer, but it's definately not ideal. I'm not sure why you need that value from the javascript, but there is usually a workaround for most problems. So bottom line, it's not possible to send a variable in javascript to php. Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-222559 Share on other sites More sharing options...
$cripts Posted April 5, 2007 Share Posted April 5, 2007 you could run a cronjob for this and store that variable for later use if thats what your trying to do Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-222563 Share on other sites More sharing options...
Azu Posted April 11, 2007 Author Share Posted April 11, 2007 There is some stuff javascript and the javascript eval function changes it into, say, "abcdefg". Without using the javascript eval function, it's a bunch of rather gibberish javascript code. I am just wandering if there is something that I can use in PHP which will act just like the javascript eval does, and thus turn turn the stuff into "abcdefg". It would be a really big waste of time to learn exactly how javascript works and make my own function for this if something like it already exists, so if I was just wandering if someone could please point me in the right direction if it does exist. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-226802 Share on other sites More sharing options...
per1os Posted April 11, 2007 Share Posted April 11, 2007 I remember seeing a function on www.php.net sometime ago regarding this. I do not remember where but I know it exists. One workaround is you do something like this: <?php $javascriptEval = file_get_contents('http://www.site.com/yourJsEvalFile.php?eval=somestringtoeval here'); ?> This is the yourJsEvalFile.html <script type="text/javascript"> <?php print "document.write(eval('" . $_GET['eval'] . "'));"; ?> </script> I have not tested it, but that should work as a workaround. I will see if I cannot find that function. Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-226964 Share on other sites More sharing options...
Azu Posted April 13, 2007 Author Share Posted April 13, 2007 Thanks, I just want it for in PHP though, not clientside. It isn't going to be displayed to the client, ever, in any way or form. It's going to be used in a cron job and should have nothing to do with anything in a browser. I just want the PHP to be able to decode javascript stuff. Thanks for your time though, I appreciate it! ^^ Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-228436 Share on other sites More sharing options...
kenrbnsn Posted April 13, 2007 Share Posted April 13, 2007 PHP can't decode the "javascript stuff", only javascript can do that. Javascript and PHP are two different languages. Ken Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-228450 Share on other sites More sharing options...
Azu Posted April 23, 2007 Author Share Posted April 23, 2007 So.. it's not possible to make a function that decodes the javascript? Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-236359 Share on other sites More sharing options...
per1os Posted April 26, 2007 Share Posted April 26, 2007 If you can get the core code of how javascript evaluates it self than you probably could, but that is just too cumbersome of a task. You have to take in account syntax and all the possibilities that can be done. Too much work for anyone to want to do it. Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-239381 Share on other sites More sharing options...
bennyboywonder Posted April 26, 2007 Share Posted April 26, 2007 am I the only one that thinks this would be a bit of a security risk, anyhow? if you manage to get js to send PHP code stored in a js variable, you must remember that the person browsing your site could easily read the code, find out the name of this variable and type "javascript: myvar = 'some_damageing_php_code; here()'" into the address bar, and then find the bit of the script that sends it off to your server and run that. This could lead to some real nasty stuff.... Quote Link to comment https://forums.phpfreaks.com/topic/45801-eval-for-php/#findComment-239421 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.