Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6653073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:13:22+00:00 2026-05-26T01:13:22+00:00

I want to access PHP(server side file variables) with JavaScript(Client side script) without using

  • 0

I want to access PHP(server side file variables) with JavaScript(Client side script) without using MySQL. e.g. i have $name=Tom; How do i access this $name variable in JavaScript? Please show code example as i am new to programming. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:13:23+00:00Added an answer on May 26, 2026 at 1:13 am

    You could do something like

    <script>
        php_variable = <?= json_encode($php_variable) ?>;
    </script>
    

    which should even let you do arrays and possibly objects. It requires PHP 5.2 or later, though. If you’re stuck without json_encode, you could wrap quotes around a call to addslashes, but that won’t let you do arrays and such.

    If your intent is to set the value within some form, you can do like

    <input type="text" name="stuff" value="<?= htmlentities($stuff) ?>">
    

    and of course, you could access that element’s value within your script if necessary.

    Two key points to take away here:

    • Since PHP is generating the page, it can output stuff as it pleases — even right in the middle of a <script> element. You can use this to transfer variables from server to client, but not vice versa. (Transferring client variables…well…that’s effectively going to require XHR or a form submit.)

    • But always* escape stuff going from PHP to anywhere — particularly if it’s going into HTML, JS, or directly into SQL. Unless you have your server set all retarded (enabling magic quotes, for example), PHP will get the data raw, and it could have special chars that will cause one or all of those to break.

    * Ok, not quite always. If you have a PHP variable that contains some HTML or JS you want to output as HTML/JS, then don’t escape it. But you should be aware of what “XSS” means, and don’t blindly output data supplied by a user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to turn off PHP's magic quotes. I don't have access to php.ini.
I want to access a MySQL database directly from JavaScript code in an HTML
I want to access MySQL through ruby on a shared linux server. I figure
So I have access to a dedicated server and want to finally create my
In my server-client model I'm using java for client side and for server side
I want to access my sql server database files in a INTEL SS4000-E storage.
I have an versioned document store which I want to access through an dict
I have a nested movie clip instance that I want to access. The path
I've written some PHP scripts to do some server-side work on a headless linux
I have a winForms NET3.5SP1 app, and want to POST data to a PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.