How To Record Urls Loading on iFrame Into MySql Db?

Programmer Experts,

I’m embarking on an interesting project to gain work experience in php. Just stuck on one thing and wondering if you can help.

You probably used Team Viewer. This is where I create a Team Viewer session and get a unique number and if I give you it then with that number you can login to my computer and see what is on my screen and you can remotely control my computer.

Creating something similar. Only difference is, you won’t remotely control my computer nor access any parts of my computer but only see what I am viewing in an iframe.

So, it is like this …

I register for a member account. I login to my member account. I add you as “friend”. Now, you can view what I am viewing on an iframe.

My homepage (member account page after I login) will show me 2 iframes. Whatever, I browse on the 1st iframe is remotely viewed by my friends like you. And whatever page you (my friend) is viewing in your 1st iframe gets shown to me on my 2nd iframe.

So, my 1st iframe records what I’m viewing to show to you, my friend, on your 2nd iframe.

And my 2nd iframe shows what page you, my friend, are viewing on your 1st iframe inside your member account.

Simple concept, really. No rocket science.

So, technically, this is how it works …

Whatever url I view in my 1st iframe (whatever url the iframe opens to and whatever links I click inside the iframe) gets recorded onto mysql like so …

COLUMN

User| Latest_Viewing_Url

UI Man|1.com

Now, your member acc home page would show the webpage I am viewing in your 2nd iframe.

Your 2nd iframe pulls that (above mentioned mysql data) data and opens to the webpage mentioned on column (Latest_Viewing_Url) position: 0.

In this example, your 2nd iframe opens to: 1.com.

When I move-on to another page (eg. by clicking a link on 1.com) then that gets not INSERTED but UPDATED on “Latest_Viewing_Url” column position: 0.

And things work vice versa for both of us.

See, I told you it is an interesting project for a beginner like me. Everything is nearly finished. But a problem:

How do I get the iframe to record (onto “Latest_Viewing_Url” column; pos: 0, all the links I click inside the iframe (in this example the url I visit after clicking a link on 1.com) ?

I can code for there to be a “Visit” or “Go To Url” button so when I click it then the url in the “Url” html text box gets recorded onto the db. But that is only recording the urls that I view by clicking the “Go” button. Imagine, I clicked a link inside the iframe. Now, that link will have no connection with the “Go” button. Hence, I’m in a puzzle how to record what links get clicked inside the iframe. If somehow, I can program the script to monitor the url field on the iframe every 5 secs for any changes so when it finds the url has changed then to record it on the db. But guess what ? I have no clue how to do that. Meaning, how to get the script to monitor what url is residing in the iframe url field. I know how to do this in Ubot Studio (.exe bot) but not php. And so, I need your brilliant help!

Care to show a few samples for all present and future newbies ? Newbies would appreciate your help for future to come!

A single line of code that notes down every url that loads in the iframe should do the trick!

What do you think ?

<html>
<head>
<title>
<?php
$user ?> Home Page
</title>
</head>
<body>
<body background=".png">

<?php
session_start();
require "conn.php";

/*Check if user is logged-in or not by checking if session is set or not.
If user is not logged-in then redirect to login page. Else, show user's account homepage.*/

if(!isset($_SESSION["user"]))
{
    header("location:login.php");
}
else
{
    $user = $_SESSION["user"];
    $sql = "SELECT * FROM $user WHERE Username = '".$user."'";
    $result = mysqli_query($conn,$sql);
    while($row = mysqli_fetch_assoc($result))
    {
        $db_id = $row["Id"];
        $db_username = $row["Username"];
        $db_forename = $row["Forename"];
        $db_surname = $row["Surname"];
        $db_email = $row["Email"];
        $db_bio = $row["Bio"];
        $db_status_to_friends = $row["Status_To_Friends"];
        $db_status_to_public = $row["Status_To_Public"];
        $db_latest_view = $row["Latest_View"];
        $db_upline_1 = $row["Upline_1"];
    
    
        //Welcome user by name.
        echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

        <?php
        //Display log-out link.
        echo "<p align='right'><a href='logout.php'>$user Log Out</a>";?>|</p><br>
    
        <?php
        //Display User's Latest View.
        echo "<br><b>Latest View:</b><br>";
        echo "$db_latest_view";?><br>
        <br>

        <?php
        //Display User's Latest Viewed Url in iFrame.?>
        <iframe src='<?php echo $db_latest_view;?>'></iframe>

        <?php
        //Display User Bio.
        echo "<br><b>Bio:</b><br>";
        echo "$db_bio";?><br>
        <br>

        <?php
    }
}
?>

</body>
</html>

​​​​​​​Ignore the tags as that is gonna get replaced by css.
Been working on this project for 2mnths, learning and all. getting tiring now. let’s finish it tonight! need to move-on to learning other stuffs! Now don’t I ?

Maybe you could run some JS code in the first iframe that runs a counter, which periodically queries the URL for the other iframe. I’ve never tried it, I don’t know if that would work - searching around google it seems that there are security issues with doing it, but there are also some very old articles. It might be that the timer option doesn’t work because your user might click too quickly for it to keep up, unless it fires very often and checks an internal variable to see if the URL has changed since it last updated the table.

I can see ways that the iframes can pass information to each other, but you can’t do it that way because you’re not in control of what’s in both of them.

I have a feeling this subject would be roaming at the subconsciously at the back of your head to come-up with a solution. Good.
I have a feeling you would come-up with a suggestion. When anythings come to your mind, mention it in this thread. Same goes for everyone.

In Ubot Studio, we have a drag and drop function $url that we drag into a variable. We assign another $function to check the variable data for any url changes. We use the WAIT command for 5 secs. Loop it so it checks every 5 secs for url changes. Hell man! Why didn’t php have such a function! Maybe, we all harass the official guys to bring-out such a handy feature! What do you guys say ?

Thanks!

It doesn’t have a function like that because PHP is a server-side language. By the time you see anything on your browser from a PHP script, the PHP code has already finished running, usually. There’s no real point making the PHP code wait for a period of time and see if a variable value has changed, because the only thing that can change it is the PHP code itself. And if it’s been waiting for five seconds, it won’t have changed it.

JavaScript in contrast runs on the browser, so if you want something to execute regularly once the page is displayed, you could use that. Sure, the JS could call some PHP on the server, which you’ll need to do once you’ve figured out how to get the URL from the other iframe, so you can store it in your database.

1 Like

I get your point. I shouldn’t get the php to wait as that would make the server wait and many requests by many users might hang the server and temporarily get the site down.
Therefore, best to get the waiting and checking done on the client side with client-side lang.
I’m guessing you don’t know javascript. Will have to see if I can find a tut or sample code on google or youtube but if you come across any then do mention the links here.

Have to get the javascript to check for url changes every 5 secs then when a change is found then force the php to respond to take the latest url off of the hands of javascript.

Thanks!

You could post the question in the JavaScript section of the board.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.