Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How's the proper way to require a file? 1

Status
Not open for further replies.

PhoenixDown

Programmer
Jul 2, 2001
279
CA
I have a file with variables:

Code:
$Somthing="123";
$Somthing2="123";
$Somthing3="123";

I want to put a require statement on my php script but it shows up in the html. I absolutely know nothing about PHP and I'm trying to learn. My script (cp.php) is below:

Code:
require ('Styles.php');

<html>
<head>
<title>Style Settings</title>
$HeaderInsert
</head>
<body bgcolor=&quot;$PageBackgroundColor&quot; text=&quot;$TextColor&quot; link=&quot;$LinkColor&quot; alink=&quot;$ActiveLinkColor&quot; vlink=&quot;$VisitedLinkColor&quot; $ExtraBodyTag>
--HTML--
</body>
</html>


PLEASE tell me what I'm doing wrong! Thank you very much! AIM: XCalvin1984
Email: calvin@puremadnezz.com
MSN: xcloud2000x@hotmail.com
Web Site: Yahoo Messenger: xcloud2000x

Contact me for any programming help and whatnot. I'll try my best to help! :)
 
I changed it to:

Code:
<?

require ('Styles.php');

echo &quot;
<html>
<head>
<title>Style Settings</title>
$HeaderInsert
</head>
<body bgcolor=\&quot;$PageBackgroundColor\&quot; text=\&quot;$TextColor\&quot; link=\&quot;$LinkColor\&quot; alink=\&quot;$ActiveLinkColor\&quot; vlink=\&quot;$VisitedLinkColor\&quot; $ExtraBodyTag>
</body>
</html>&quot;;

?>

It still doesn't work. Check out the URL to the file! AIM: XCalvin1984
Email: calvin@puremadnezz.com
MSN: xcloud2000x@hotmail.com
Web Site: Yahoo Messenger: xcloud2000x

Contact me for any programming help and whatnot. I'll try my best to help! :)
 
When you say it still doesn't work, you need to explain more:

Do you get any error messages?

What in fact does happen when you request the page? Do you get a blank web page?

If the PHP code still shows, then try using the full PHP tag: &quot;<?php&quot;.

 
I changed '<?' to '<?php' and it still didn't work.

There are no error codes. See the following files for the source code:


AIM: XCalvin1984
Email: calvin@puremadnezz.com
MSN: xcloud2000x@hotmail.com
Web Site: Yahoo Messenger: xcloud2000x

Contact me for any programming help and whatnot. I'll try my best to help! :)
 
Calvin0

I had a quick look at your code and have two suggestions:

1. I think the main problem is your Styles.php file. When a file is
Code:
require
d or
Code:
include
d, it is fetched as HTML, therefore you need to put
Code:
<?php
and
Code:
?>
tags around php code in it as well, ie...
Code:
cp.php:
Code:
<?php
require('Styles.php');
?>
<!--Other HTML stuff-->
Code:
Styles.php:
Code:
<?php
$Something = &quot;123&quot;;
// Other PHP stuff
?>

I hope you can see the sense of this.

2. Secondly, I think you have a typo in Styles.php - there are some unescaped quotes in your
Code:
$HeaderInsert=
line.

Hope this helps
-Rob
 
Thank you!! That fixed it!! AIM: XCalvin1984
Email: calvin@puremadnezz.com
MSN: xcloud2000x@hotmail.com
Web Site: Yahoo Messenger: xcloud2000x

Contact me for any programming help and whatnot. I'll try my best to help! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top