Jump to content

Eval for PHP?


Azu

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! ^^

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.