How to capture and get javascript output using PHP ?

Posted on 2011-04-23
Last Modified: 2012-05-11

I would like to request an assistant.

I have the following javascript loaded in "livechat.php" :

<script language="javascript" src=""></script>

The script will display/load the following image when the user using it is online :

When the user using it is not online, it will display the following :

The problem, is that this images does not shows in browser VIEW SOURCE, it just being loaded on the fly.

I would like anybody can assist in using CURL or anything else in php to detect/capture this behaviour :


if (staffonline.gif == is found in livechat.php)
{ do something }

if (staffoffline.gif == is found in livechat.php)
{ do something else}

Appreciates anybody assistant.

Thank you.
Question by:smksa
    LVL 6

    Expert Comment

    I fear you cannot do it, since the javascript is on the client side and the php is in the server side.
    You can although get some infos if the javascript save it as cookie and you recover with the php from it.
    the php normally generate the web page on the server, sends to the client, and then the client executes the javascript. so there is no interface to interact between javascript and php directly, only by cookies or by post and get methods. the javascript could also change urls to send a variable and telling the php script that the user is offline the next time the php generates a webpage
    LVL 2

    Author Comment

    But, i believe if using CURL , the PHP will crawl to the website as if it is a client right ? Thus, can it detect the images ?
    LVL 6

    Accepted Solution

    If a user is online it authentificated with a server and saved it as a cookie info.Or how the user connects with the server? Another way would be use ajax. Load the page till you get the javascriupt thing, and then use an ajax request with the right parameters to get the rest of the webpage

    Featured Post

    Training Course: Android App Development

    This course will involve creating widgets, customize list view, grid view, spinners, etc. Creating applications using audio, video, and SQLite database. Ending with publication on Google Play.

    Join & Write a Comment

    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now