Why does the PHP script not run if opened by the pc, but runs if opened in localhost?

Asked

Viewed 304 times

-2

Already I warn you that I am not with any problem and, alias, I just solved one that refers to this question but anyway, I wanted to know (out of curiosity) why a php script does not run if I open the file by computer, but if I type the host location address it runs normally?

<html>
	<head>
		<META CHARSET="UTF-8">
		<META NAME="author" VALUE="Fernando Aguiar Pinedo">
		<LINK REL="stylesheet" HREF="css.css">
		<LINK REL="shortcut icon" HREF="favicon.ico">
	</head>
	<body>
		<div id="cabeçalho">
			<h1>Music Downloader</h1>
			<p>Download Your Music Here</p>
		</div>
		<div id="filterlist">
			<ul>
				<h1 style="font-family:calibri; margin:5px; text-align:center;">Genre</h1>
				<li>Rock</li>
				<li>Eletronic</li>
				<li>Pop</li>
				<li>Reggae</li>
				<li>Hip Hop</li>
				<li>Anime</li>
				<li>Video Game</li>
			</ul>
			<ul>
				<h1 style="font-family:calibri; margin:5px; text-align:center;">Language</h1>
				<li>English</li>
				<li>Japanese</li>
				<li>French</li>
				<li>Brazilian</li>
				<li>Chinese</li>
				<li>German</li>
				<li>Spanish</li>
			</ul>
		</div>
		<div id="content"> <!--Conteúdo Aqui-->
			<?php
				include ("connectsql.php");
				$consulta = "SELECT * FROM songs";
				$result = mysqli_query($link, $consulta) or die(mysqli_error());
	
				if($result){
					while($row = mysqli_fetch_array($result)){
						$name = $row['Song'];
			?>
			<p><?php echo "$name"; ?></p>
			
			<?php
					}
				}
			?>
		</div> 
		<!--Até Aqui-->
	</body>
</html>

In div "content" php does not run directly from the computer, only if it is opened by the internet by typing the localhost address.

2 answers

1

Why the browser cannot interpret a language that runs on the server side by itself. That’s why we use WAMP, XAMPP, Apache, among others. This applies to any language that makes the Server-Side.

0


The PHP is a language back-end* that runs on the server usually the APACHE*, the browser has no power to interpret this type of language.

What is apache? The Server HTTP Number One on the Internet, the Apache HTTP Server Project is an effort to develop and maintain a server HTTP open source for modern operating systems, including UNIX and Windows. The goal of this project is to provide a secure, efficient and extensible server that provides services HTTP in sync with standards HTTP current.

Let’s say you want to save your precious connection and develop everything locally. In this case, you will need to install a web server, such as the » Apache, of course the » PHP. You probably also want to install a database, such as » Mysql.

What is back-end?

Back-end As the name suggests, the back-end developer works on the "back" part of the application. He is responsible, in general terms, for implementing the business rule.

In a web application, this developer, when focused, does not touch the visual part of the application. By dealing with the business rule, sometimes a systems programmer, such as from commercial and even scientific applications, can be called a back-end developer. And usually, in these applications, this developer works a little bit with the visual part. Therefore, for this article, the back-end developer taken into account is the developer of web applications.

When we talk about back-end web development, we come across several languages, such as Go, Clojure, C#, PHP, Java, Python, Ruby, among others. Each has advantages and disadvantages in relation to the use in web development, as well as in the labor market.

inserir a descrição da imagem aqui References:

http://httpd.apache.org/
http://www.php.net/
https://www.treinaweb.com.br/blog/o-que-e-front-end-e-back-end/

  • 1

    Thank you for the reply, although not to the point, explained some of my doubts!! vlw.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.