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 1112799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:45:50+00:00 2026-05-17T02:45:50+00:00

I have a big validation JS script. I want to put this script to

  • 0

I have a big validation JS script. I want to put this script to be external JS.

Everything works fine with this, but in the JS i use cookie to handle the my user form junctions.

And besides, i use PHP in this JS.

If the JS in the html, then works. But if i put it to external, then no.

For example:

External JS:

$(document).ready(function() {

     var test = $.cookie('tet');
     $.cookie('tet','8'); 

    <?php
     if (isset($_SESSION['main_check_a'])) {
     echo "$.cookie('tet','1');";
    ?>
}}

}

How can i pass this PHP code to my external JS?

  • 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-17T02:45:51+00:00Added an answer on May 17, 2026 at 2:45 am

    You need to either

    • Have the JS file parsed by PHP, by naming it filename.js.php or by changing the server’s configuration for PHP to parse .js files. This is not optimal however, because a resource-intensive PHP instance will be started for every script request.

    • Alternatively, much better IMO, do the necessary checks in a <script> tag in the embedding document, and store the results in JS variables that the embedded external scripts can query. This way, your script files can stay static.

      In your case, this would mean something like this. In the main document:

      <script> 
      <?php 
         echo "main_check_a = "; 
         echo (isset($_SESSION['main_check_a']) ? "true" : "false"); 
       ?>
      </script>
      
      
      .... now, include external JS files ....
      

      this will give you the JavaScript variable main_check_a that you can use in your external scripts.

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

Sidebar

Related Questions

I have big set of urls and I want to implement an autocompletion. I
I have big dataset (but the following is small one for example). I can
i have a big problem... i have this map HashMap<Long, String> examValues; It gets
I have big problems with stopping a service, which plays audio file. I want
I've got a really big ModelForm and want to implement Ketchup jquery validation .
I have a file (image) upload script in PHP that I use to upload
I have a validation for big file size in a try block, after throwing
We are using this coding to handle the clicking of the big red X
I have an MVC 3 application that works fine when running locally from visual
I have a fairly complex and big Model called Task . In this object

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.