Menu
Every visitor on my site gets an automatic MySQL table with stats like screen size, ip, browser etc.
Now everything is saved in the user table, but there’s a little problem.
How can I update a javascript code like screen.width?
[code=php]Update user SET screen=screen.width WHERE ip=$ip;
That’s not working… Is there a PHP code for it? Or how can I fix it?
Greetz tAK
JavaScript is a client-side language, PHP/MySQL are server-side, hence they don't speak directly to one another. The only way (I know of) to pass values from JavaScript to PHP is to create an invisible form and populate it with the information that you'd like to pass (or pass it in a URL as in a GET statement and then use PHP to interpret the GET).[/QUOTE]
Actually javascript can send information to php behind the scenes without a new page load being necessary.[/QUOTE]
[code=html]<iframe src=stats.php?screen=<script>document.write(screen.width+"x"+screen.height);</script>&colors=<script>document.write(screen.colorDepth);</script>></iframe>[/code]
[B]The XMLHttpRequest Object[/B]
This object, first implemented by Microsoft as an ActiveX object but now also available as a native object within both Mozilla and Apple's Safari browser, enables JavaScript to make HTTP requests to a remote server without the need to reload the page. In essence, HTTP requests can be made and responses received, completely in the background and without the user experiencing any visual interruptions.[/QUOTE]
But now I have another question. Is there a way to auto-refresh PHP code?
Let's say Online() is a function that reads the SQL-database for online visitors, but after ten minutes of reading the info, maybe all visitors are gone and still it gives the same number... Is there a way to autorefresh only a little bit of PHP-code?[/quote]
Why not reply to old threads?[/QUOTE]Because it's not helpful to the OP.
my question is :Javascript on the client sends the username to the server. This request is handled by PHP or other serverside scripting language which checks the database to see if the username is vacant and returns the result to javascript on the client. All is done in the background without the need for a page reload.
what tools or script language to create something like that??Php?javascript?or what??[/QUOTE]
// Create new script element, set its relative URL, and load it
// The script inside CheckAvailability.php will change this page's "status" field automatically...
script = document.createElement('script');
script.src = 'CheckAvailability.php?username=' +username;
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
<!-- Availability status field -->
<span id="status"></span>
$sqluser = "YOUR_USER_HERE"; // MySql Username
$sqlpass = "YOUR_PASS_HERE"; // MySql Password
$sqlhost = "YOUR_HOST_HERE"; // MySql Host Address
$sqldb = "YOUR_DB_HERE"; // MySql Database Name
mysql_connect($sqlhost, $sqluser, $sqlpass); // Connecting To MySql
mysql_select_db($sqldb); // Selecting MySql Database
$results = mysql_query("SELECT * FROM TblUsers WHERE USERNAME='$username'"); // Run A Query To See If The Username exists
$numResults = mysql_num_rows($results); // Number Of Results Of The Query
if ($numResults > 0) { // If username exists
if ($username == "") {
$status = "Username is invalid"; // Invalid username... checks could be more vigorous
} else {
$status = "Username not available"; // Unavailable username
}
} else {
$status = "Username available"; // Available username
}
old threads help new readers. Fora are not just for the benefit of the OP.[/QUOTE]
Ok i'm a total noob to Java Script, what i want to do is get a number from a php page an then put it into an if statement.
So here goes the php page is completely blank no html tags or anything. The only thing on the page is an number for example number 4.
And what I need the Java Script to do is every 3 mins without refreshing the page, compare the the numbers
if (num_from_php_page > 6)
{do this}
I'm not sure if Java Script can even do this, so any help or advice would be much appreciated.[/QUOTE]
What do you mean "yours"? I did not post any questions or answers here. I just found this thread while researching this issue, and I found this thread, including the newer posts, relevant and helpful to my needs.
Cheers.[/QUOTE]
0.1.9 — BETA 5.28