• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

[php]

The Red Guy

Dork
NLC
Code:
<?php
$new = 1;
?>
<html><head></head><body>
<?php
echo $new;
?>
</body></html>

Would it print the number 1 to the screen, or would it be blank? I thought this was easier than have an entire paragraph of text. :)
 
Which means that variables are global in the file declared, and even though you close one instance of php and open another, it's still there?
 
Originally posted by The Red Guy
Which means that variables are global in the file declared, and even though you close one instance of php and open another, it's still there?

Exactly.

[Edit]

You can even declare the variable from a file

and include it at the top of the php page

PHP:
<?php include('variabe.inc.php'); ?>

[Edit]

Thank You =)
 
Last edited:
Originally posted by Robert

PHP:
<?php include('variabe.php.inc'); ?>
the proper way using include is by saving the file as .php like
PHP:
<?php include 'variable.inc.php'; ?>
because people will be able to see whats inside when they call a .inc file
 
Originally posted by kabatak
the proper way using include is by saving the file as .php like
PHP:
<?php include 'variable.inc.php'; ?>
because people will be able to see whats inside when they call a .inc file

Hmm it was a mistake that's what I meant. Thank You.
 
After some learning of the language, I'm a getting the hang of it now. However, does it even matter if the file is named inappropriately? I mean, I could include a file like extensions.inc and nothing goes wrong!
 
Last edited:
Originally posted by The Red Guy
I mean, I could include a file like extensions.inc and nothing goes wrong!
You could include any file, but the whole point of the end being .php is so that if a user calls that file in a browser window, they wont see what is inside it. Whereas if they called a .inc it would prompt to download and they could see the info in it.
 
Originally posted by The Red Guy
After some learning of the language, I'm a getting the hang of it now. However, does it even matter if the file is named inappropriately? I mean, I could include a file like extensions.inc and nothing goes wrong!

as long as you put the <?php and ?> tags in this document it wont matter, if you dont it will be printed to the browser as just normal text.
 
Actually, if you browse to a file named "*.inc", it will prompt you to download the file, no matter the contents. That is, of course, unless you specify files with an "inc" extension to be parsed as "php".

The reason this is important is that if you are including any sensitive details (such as mysql connection details), you want the info to be secure. As stated, always include files as "inc.php" or simply"php" to prevent any security problems.
 
Back
Top