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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:55:33+00:00 2026-06-07T10:55:33+00:00

I have a Javascript variable screenName for twitter users. When they connect to my

  • 0

I have a Javascript variable screenName for twitter users. When they connect to my site, I want a php script to write their name in a txt file. How could I do this. I looked into writing files with AJAX but no luck.

<script type="text/javascript">

twttr.anywhere(function (T) {
    var currentUser,
        screenName,
        profileImage,
        profileImageTag;
    if (T.isConnected()) {
        currentUser = T.currentUser;
        screenName = currentUser.data('screen_name');
        $('#twitter-connect-placeholder').append("<p style='color:white;text-shadow:none;'>Howdy " +" " + screenName + "!");
        var screenName = "<?= $js ?>";
    } 
});
</script>

<?php
$check = $_GET['track'];


if ($check == '1') {
    $fp = fopen('data.txt', 'a');
    fwrite($fp, "{$js}");
    fclose($fp);
}
?>

If you view the source screenName equals “”

Any ideas on this?

  • 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-07T10:55:36+00:00Added an answer on June 7, 2026 at 10:55 am

    In order to approach the problem, you’ll need to understand that the PHP is executed on the server side, before the page is sent to the user, and the Javascript is executed on the client side, in the user’s browser, i.e. after the PHP code. Obviously, you need the events to happen in the reverse order. An example implementation follows:

    Using jQuery, you can do:

    if (T.isConnected()) {
        var currentUser = T.currentUser;
        var screenName = currentUser.data('screen_name');
        $.post(
            '/writename.php',      // request url
            {'name' : screenName}, // POST data
            function() {           // optional callback
                alert("done!");
            }
        );
    }
    

    And, in your writename.php:

    if ($_POST['name']) {
        $fp = fopen('data.txt', 'a');
        fwrite($fp, $_POST['name']);
        fclose($fp);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable in javascript and a multidimensional array in PHP. I want
I have a JavaScript variable that I echo out using PHP which is shown
I have a php script that is reading a file in (file_get_contents). I want
I have a JavaScript variable which contains the name of a JavaScript function. This
I have a javascript variable: var foo='<script type=text/javascript>alert(Hello World);<\/script>' The variable is inserted with
i have javascript as below html=<th>+<?php echo __(); ?>+</th>; I want to add another
I have name JavaScript variable. If variable name contains less than 4 characters I
I have a Javascript variable which I am setting a PHP variable to. function
I have a javascript variable that I want to include it in my html
I have a javascript variable, for example: var s = <result>Success</result><name>George</name>; How can I

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.