Jump to content

eval error, help me!

- - - - -

  • Please log in to reply
10 replies to this topic

#1
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
hi guys

please check my code

bgstr.js file:

$variable = 13;


index.php [run file]

<?php


$getContent = file_get_contents("http://www.mysite.com/bgstr.js");


eval($getContent);

echo $variable;


?>


error:
Parse error: syntax error, unexpected T_VARIABLE in index.php(4) : eval()'d code on line 1


why show this error?

thank you

#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US

lol33d said:

<?php


$getContent = file_get_contents("http://www.mysite.com/bgstr.js");


eval($getContent);

echo $variable;


?> 

Try this:
<?php


$getContent = file_get_contents("http://www.mysite.com/bgstr.js");


echo $getContent;


?> 

What would the above code output?

#3
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
do u mean about eval?
PHP: eval - Manual

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Do you understand what eval does?

Why are you running it on a Javascript document?

What is your intended purpose?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
this javascript is out source and orginal code is

var variable = 13;  

i can change to $variable = 13; with replace string

i need change to php code and i use of this

please help thank you

#6
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
What I was asking is, are you sure that $getContent contains the right code, when you perform eval () on it? That is why I told you to try debugging $getContent, to check to make sure that part is what you think it should be.

#7
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
please give me a correct code

#8
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
Well, technically, in JavaScript,
eval ("var variable= 13;"); 
would work, so I'm guessing that in PHP,
eval ("$variable= 13;"); 
should also work. The thing now, I think, is to make sure that what you're passing to eval () as an argument is "$variable= 13;" , and not "404 File Not Found" , or anything of that type.

I already posted code that would help you ensure that.

#9
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
yes thank you

but i need get content then show and eval

#10
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
What?

What's wrong with showing what $getContent is, just so you can check to make sure it works, and once you get everything working, taking out the line that shows $getContent? I do that type of stuff almost all the time.

#11
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You need to understand that eval() in PHP will interpret PHP code.

If you are using AJAX, then the PHP script will send content to the Javascript. If you are modifying Javascript, then you will need to place it in a file - or simply display it to screen so that it may be parsed by a browser.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users