SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript inside php variable?

    How can i have:

    $myvar= <...js> document.bgColor <js...>

    Thank you.

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    exactly the way you did it, but with a quotes around js because it's a string.
    Code:
     $myvar= 'document.bgColor'

  3. #3
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In a properly escaped string. PHP just prints out the JS no different than any other output.

  4. #4
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But, Hey, What are you tying to do? I hope you just want to dynamically print out javascript code in the HTML page!

  5. #5
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript is a client side processing, php is a server side processing. You can store information with javascript in cookies, but will need to make a trip back to the server for php to use the information for processing.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need to do exactly what Hammer65 sad. I need to run js inside php variable so i get results in variable from js.

    Reason why i need this is because of "document.referrer", i have used php referrer but with no success because js code is included on third pary web site and referrer is always main script server. I need to track referrer's to web site where js is included.

  7. #7
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by iDeaStuff
    I need to do exactly what Hammer65 sad. I need to run js inside php variable so i get results in variable from js.
    You are out of luck. It doesn't work that way. PHP runs in server and JS, on the other hand, runs on the browsers. Then don't work together at the same time.

  8. #8
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP won't execute the JS. It can only print it out. The only thing that will execute the JS is the browser. Getting an accurate referrer is hard for a reason. These days people don't necessarily want you to know where they have been on the web.

    Having said that, though it's not directly related to the OP's question, if any of you C/C++ programmers want to craft a PHP extension that embeds the gekko/spider monkey engine, I'll be the first one to download it.

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kailash Badu View Post
    You are out of luck. It doesn't work that way. PHP runs in server and JS, on the other hand, runs on the browsers. Then don't work together at the same time.
    Is there any other solution for referrer ? Or it's just impossible?

  10. #10
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Only the $_SERVER value, and that won't always be there.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •