SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict chartahir's Avatar
    Join Date
    Oct 2006
    Location
    Karachi, Pakistan
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Access php variables using JS ???

    Can i access php variables using JS , if yes then how ?
    chartahir

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not as such. PHP is executed on the server, while JavaScript is executed in the client browser.

    You can, however, generate JavaScript code via PHP on the server side. That allows you to use PHP variables when generating the script code. They won't be available when the script is executed, though.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can i access php variables using JS , if yes then how ?
    This is the way it works. A browser requests a php page from the server. Before sending the page back, the server sees to it that all the php on the page is executed with the result being a page containing only html and javascript. Then that page is sent to the browser. The browser has no idea whether the page it received was the result of a php script or whether it was a just a plain html page from the very start. In fact, a browser is unaware that php has even been invented yet. Similarly, javascript is unaware of the existence of php. And php is almost wholly unaware of the existence of browsers, html, or javascript. As in Plato's Allegory of the Cave, php can see shadows on the cave wall in the form of GET and POST variables of something that exists outside itself, but it has no idea what that thing's true nature is.


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
  •