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

  • SEARCH
  • Home
  • 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 8066487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:00:48+00:00 2026-06-05T12:00:48+00:00

I have a php file as my main page, and I want to pass

  • 0

I have a php file as my main page, and I want to pass a php variable to an external js file that is drawn with php. I have several php’d external js files that work fine but are “not” dependent on php from the main page. Some are dependent on JavaScript from the main page, but I want to move away from that. My intentions are to keep the main page clean by limiting the amount of JavaScript on it, by increasing dynamics, and to allow better site management.

Maybe if I understood the natural relationship of external files to the calling page, i dun know. For instance, the code below is some of my current code, and it assumes the external js script, being the php file it is, sees “functions.php” and $sel_entity from the main page. However, it does not seem to work that way. I am guessing maybe functions.php needs to be included in the external file, but no clue with $sel_entity. I am aware I could echo variables to a js variable on the main page, but I need something more dynamic for my plans. Any help here would be great. Thank you!

For instance, the main page is something like:

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php  $sel_entity = $_GET['entity']; ?>
...//bunches of code 
<script type="text/javascript" src="javascripts/lines.php"></script>

Then the js file lines.php is something like:

<?php
 Header("content-type: application/x-javascript");
  $job_set = get_jobs($_GET['entity']);                     
  while ($job = mysql_fetch_array($job_set)) {
    echo "
        var jobLine";
echo $job["Project_ID"];
echo " = [new google.maps.LatLng(lati, longi),
";
$jobIdCoords = get_jobCoord_by_id($job["Project_ID"]);
echo " new google.maps.LatLng(";
echo $jobIdCoords['lat'] . ", ";
echo $jobIdCoords['long'] . ")]; ";
                    }
  ...// bunches more code
?>  
  • 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-06-05T12:00:50+00:00Added an answer on June 5, 2026 at 12:00 pm

    The best way would be to use $_SESSION, but be sure to start the session in the “js” file.

    <?php
    session_start();
    $_SESSION["foo"] = "bar";
    ?>
    <script type="text/javascript" src="javascripts/lines.php"></script>
    

    And then the JS file:

    <?php
    Header("content-type: application/x-javascript");
    session_start();
    echo 'var foo = "'.$_SESSION["foo"].'";';
    ?>
    alert(foo);
    

    However, you should be able to also use $_GET like so:

    <script type="text/javascript" src="javascripts/lines.php?foo=bar"></script>
    

    And the “JS” file:

    <?php
    Header("content-type: application/x-javascript");
    echo 'var foo = "'.$_GET["foo"].'";';
    ?>
    alert(foo);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page (main.php) which loads content from an external PHP file (rpc.php).
I want to display 404 error page for that i have made error404.php file
I have two files, csform.php and process.php. Csform.php is the main page with the
I have a PHP File with something like this: <script type=text/javascript> var page =
I have a PHP file that contains a large array (about 90KB). I'm considering
i have a php file which stores a variable, and i need to create
I have a php file list.php <?php $arr=array('444','555'); echo var_export($arr); ?> Now I want
I have a PHP file with shell commands running through a screen, the commands
I have a php file setup to pull through ONE XML data feed, What
I have a php file which checks for login and password from users database,

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.