#php vs JS
1 messages · Page 1 of 1 (latest)
<@&987246964494204979> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
not sure who "they" is but this is a simple and fairly useful setup. Thats not 'front end' tho. Thats full stack. PHP is a backend language, but its also responsible for outputting the HTML buffer. JS is similar to PHP in that it can contain both HTML/css/frontend stuff, as well as 'backend' logic.
These things (JS and PHP) go together tho, unless you're using nodeJS as the backend server, which is possible but I dont prefer it. Most of the time a website language is referred to by the backend (e.g. PHP, Node (JS), Java (Spring), C# (ASP.NET), etc). Everything else (HTML, CSS/SASS, JavaScript/Typescript, etc) is going to basically be the same. The generation of the HTML will differ though.
Then each backend server can communicate with any database, some are easier/harder than others. like in PHP it is pretty easy to connect to mysql (unless ur php.ini disables it).
So in your proposed setup yeah you'd have PHP on the backend connecting with an SQL database, then that PHP backend also generates the HTML (preferably with separation of duties [frontend and backend code loosely coupled / isolated]). Then CSS frontend, with Javascript for extra frontend functionality, as well as intercepting HTML submissions
Some professional businesses work in PHP, but not many
well, thats a strangely incoherent question
Most major companies use more robust solutions
tons work in php, but not the ones that pay well ^
lol
I thought everything that happens on the side of the client
was frontend
even database querys
those arent and should never be done by the client
still the client doesnt do that
Yeah, sorry about that
Not a dig
the browser/javascript sends data to the backend server which processes it, communicates with the database (preferably after preventing sql injection), figures out what it wants to respond with, then sends it back to JS or the browser
It's just a sign you are coming at this from a strange base
but then
you don't use php on the front end?
on facebook, they use it
facebook and php are funny. They rewrote an entire php interpreter to speed it up with C++
thats just the url
it is in a variant of php, but you dont necessarily have to respond to /login.php
i could make my java server respond to login.php
a php server will look for a visible /login.php file for the above request, and if it doesn't it should go to index.php
assuming login.php exists, then it starts executing the script such as
<?php
require_once "dbcom.inc.php";
require_once "anythingelse.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login - Facebook</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/main.css">
</head>
<body>
<h1>Login Senpai</h1>
</body>
</html>```
in this case PHP isnt being used for anything to alter the html stream
so
this is an exception
normally, you wouldn't use php on the front?
just JS
and then node.js or php on the side of the dbms
so you can like send data from the front with JS to the back
that example is still not php on the frontend explicitly
PHP is a server side language
The PHP server listens for requests, see's /login.php or /login, and looks for a script to execute, under which it collects HTML output strings', and returns the result to the user after the script executes
you can also have classes and datastructures and database connections, fancy algorithms, whatever, in the php server. None of that is given to the user. Only what is echoed or directly passed to the output stream
Node.js & PHP, when on a Java discord server? 🤨
I don't get it
this is why originally i said PHP is sort of full stack. Both backend and frontend code are written in it (preferably in separate places). Its not explicitly one of the other. Whereas HTML and CSS are literally only frontend
okay, now I do
and technically javascript in the browser is front end but also can act like backend for advanced logic
let me make a short example with both
okay
PHP is solely back-end, it does not run client-side. It serves content which gets rendered client-side
true, but frontend developers could still write HTML inside of PHP files, so while it technically is back-end from the client-server architecture, it can be front-end to the developer
but let's say the DBMS with PHP gives you (the user), data. Can't you use php on the Front end to print it on the screen?, like
<?php
$stuff_recieved = recieve_data();
foreach($stuff_recieved as $i) {
echo ...
}
?>
thats what I mean with php on the front
its executing on the backend to provide content to the user's client after the script executes
ohh
but
if I want to make the system more dinamic
so you don't have to reload all the content of the page, every time the DBMS does php stuff and gives you the new html
can't you like
You could use something like AJAX
<?php
function factorial(int $n): int {
$result = 1;
for ($i = 2; $i <= $n; $i++) {
$result *= $i;
}
return $result;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Factorial Numbers</h1>
<div>
<table>
<thead>
<tr>
<td>n</td>
<td>n!</td>
</tr>
</thead>
<tbody>
<?php
for ($n = 0; $n < 15; $n++) {
$nFact = factorial($n);
echo "<tr><td>$n</td><td>$nFact</td></tr>";
}
?>
</tbody>
</table>
</div>
</body>
</html>
and yes you can use ajax via javascript
which is part of the jquery library
e.g.
This seems like a strange question to ask on a Java server
Keep in mind, Javascript is not Java. They are completely dfferent
#Other 
Yeah, guess you can ask about any language. Just thought this would be something to ask in a server which revolves around JS more, or even web dev in general

for example, let's say you want to change your profile picture,
you, the user, click on the button, upload the pic, send it to the php DBMS
it manipulates the SQL, you reload the page, and the DBMS returns you the changes,
now you can see your new profile pic.
It could take a while if the system is slow, so can't you like "fake the change" on the front, so it is faster
seemingly?, in that case, you wouldn't use php?, like
<? php
<img src = $file_new_pic>
that "send it to the php dbms", wouldn't you do that with php? on the front
php on the front
yes and no. Thats not how PHP works directly, it is the thing that works with the DBMS and gives the content, but not faking the change
I know
lmao
you could instead do ```js
$("#update-profile-picture-button").on("click", function() {
$.post({
url: '/profile/update',
data: {
image: image
},
success: function(response) {
$("#profile-image").html(<img src=${response.source} class="profile-main-image">)
},
error: function(xhr, status, error {
console.log("oops!");
}
})
});```
on the frontend client code, then on /profile/update.php
// intercept POST and get name
// update in database
return json_encode(["source": $newImageSrc]);```
Detected code, here are some useful tools:
echo*
well, thank you