New at PHP basic questions.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TuNiX
Forum Newbie
Posts: 2
Joined: Fri May 15, 2009 4:45 pm

New at PHP basic questions.

Post by TuNiX »

Hi all!

this is my first post and im very new at PHP.
i have taken the liberty of checking out some PHP tutorials more specifically at http://www.php.net/tut.php

Im a bit confused on how PHP works, is it code that goes inside of .HTML or .PHP pages? like Java Script and VB Script? or does it sit on the server side and is it called into use by a piece of code in the .HTML or .PHP page?

can anyone just look at your PHP code? i see PHP can actually open a connection to a SQL database and read and write to it, how come people cant just Right click > view source, and steal the login information to your SQl database? i think im missing something important here lol

IF that's confusing. Heres what i was trying to do, i went online and doenloaded some sample PHP code examples and tried to implement them to see if they work but what happened was the PHP code was just displayed as plain text when i tried to navigate to the page.

I am using Apache and PHP5 is installed by my shared hosting provider.

Thanks in advance guys.
User avatar
Chrisaster
Forum Newbie
Posts: 8
Joined: Fri May 15, 2009 2:13 pm
Location: England

Re: New at PHP basic questions.

Post by Chrisaster »

PHP is server-side and all files that contain PHP tags must be in .php format. PHP files can still contain languages other than PHP.

That's about all I know :D
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: New at PHP basic questions.

Post by Benjamin »

TuNiX wrote:but what happened was the PHP code was just displayed as plain text when i tried to navigate to the page.
What was the file extension of the page?
TuNiX
Forum Newbie
Posts: 2
Joined: Fri May 15, 2009 4:45 pm

Re: New at PHP basic questions.

Post by TuNiX »

it was .PHP, ill explain what i did:

i went to http://www.phpbuilder.com/snippet/downl ... pet&id=887

and copied all that code into notepad on windows and added my html headers and what n ot "<html> <body> ect..."

i then saved the file as testPHPcode.PHP

and then i used filezilla to upload that .PHP file to my PHP5 enabled server

and it still was projected as plain text.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: New at PHP basic questions.

Post by Darhazer »

Probably your PHP server is not configured to work with short tags
<? is the short version of <?php and not all servers recognize it (it depends of php.ini settings)
So try to use <?php at the beginning, instead of just <?
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: New at PHP basic questions.

Post by Griven »

Im a bit confused on how PHP works, is it code that goes inside of .HTML or .PHP pages? like Java Script and VB Script? or does it sit on the server side and is it called into use by a piece of code in the .HTML or .PHP page?
PHP is server-side code that is executed at runtime (when the page is requested by a user's web browser).

For PHP code to execute, it must be in a file with an extension of .php. Using any other extension will cause the source code to be displayed in the user's browser. The file extension is important, in that it tells the web server how to handle the code that's written inside of it. Without that .php extension, the file does not get passed to the PHP parser. Having said that, let me also add that HTML and PHP can co-exist in the same .php file.

For example, the following page will work just fine.

index.php

Code: Select all

 
<html>
<head>
<title>My first PHP script</title>
</head>
<body>
  <?php
    echo "PHP tags can sit inside of HTML, and <i>vice versa</i>.";
  ?>
</body>
</html>
 
can anyone just look at your PHP code? i see PHP can actually open a connection to a SQL database and read and write to it, how come people cant just Right click > view source, and steal the login information to your SQl database? i think im missing something important here
There are only a few circumstances where people can see your PHP source code.
1.) They have access to the web server's file system, like you do
2.) The web server does not have PHP installed, and therefore does not transform your PHP into HTML
3.) You put PHP in a file that does not have the .php extension.

As mentioned in item 2 above, when PHP is parsed by the server, it is transformed into HTML and only then passed to the user's web browser. So, even if they view the source for the web page, they won't actually be seeing your PHP source code.
Post Reply