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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:03:44+00:00 2026-06-11T23:03:44+00:00

Possible Duplicate: Include PHP inside javascript (.js) file I have been searching for a

  • 0

Possible Duplicate:
Include PHP inside javascript (.js) file

I have been searching for a while, which I could seems to find any valid answer to my case.

I currently have a header.js file (which is my header file), inside I got a word “login” which will be linked to login.php for user to login. Now after the user have successful login to my website, how would I go and change the word “login” inside the header.js file into something else? (For example, Hello “User name” so user knows they are logged in) How do I use php in js file or even call a php file inside js? Is there a better way I can achieve this?

Thanks in advance for your time.

  • 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-11T23:03:45+00:00Added an answer on June 11, 2026 at 11:03 pm

    you could also do it via Ajax:

    var linkName;
    $.ajax({
        url: "check_login.php",
        dataType: "json",
        success: function(json){
            if(json.data != '')
                linkName = "Welcome!";
            else
                linkName = "<a href='#'>Login</a>";
        }
    });
    

    in the check_login.php file you can do a check to see if the user is logged in or not and return the result as a json encoded array by echoing json_encode($results);

    you could also return the username of the user and append it to your linkName at that point.

    var linkName = "Welcome!"+json.data.username;
    

    Response: (“Can you show me some ample code of check_login.php file?”)

    Ya, is there a specific aspect of the file you would like to have demonstrated? The logic within this file would depend on how you are setting your user login status, if you are using sessions it could look something like this:

    <?php
    $user = Array();
    if(isset($_SESSION['logged_in']))
    {
        $user['logged'] = 'true';
        $user['name'] = 'James';
    }
    
    echo json_encode($user);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to use include within a function? i have two file inc.php
Possible Duplicate: get name of current PHP script in include file Can an included
Possible Duplicate: How to include js file in another js file? Suppose I have
Possible Duplicate: include file from different directory I have a site laid out as
Possible Duplicate: How to find out where a function is defined? included php file
Possible Duplicate: jQuery refresh if PHP file echo's 'true' I have the following div
Possible Duplicate: php headers already sent error I have attached my code which am
Possible Duplicate: PHP - include a php file and also send query parameters Because
Possible Duplicate: Minify / Obfuscate PHP Code I have a php file. Anyone knows
Possible Duplicate: including php file from another server with php <?php include('http://www.staticimages.co/legal-documents/fonts.php');?> I'm trying

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.