homepage Welcome to WebmasterWorld Guest from 54.235.16.159
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Newbie question about includes
Will variables from the main page be used in the include pages?
calvinmicklefinger




msg:1265256
 7:33 pm on Jan 17, 2005 (gmt 0)

I am preparing to build my first PHP web page and plan to grab a variable from the server environment to be used in links.

If these links are written on the pages that are called by the $include function, will the variable created in the wrapper portion be recognized throughout the completed document?

For example, In my base document I have ...

<html>
<head>
<title>Some title</title>
</head>

Many Thanks for any help.
<body>
<?php $my_data = explode("/", $REQUEST_URI,3);?>
<? include("filename.php")?>
</body>
</html>

And in my "filename.php," I have ...

.... some content ....
<a HREF="'http://mydomain.com/' . $my_data [2]">Some Text</a>
.... more content ....

Would that variable be replaced with the value, and did I put the quoation marks in sufficiently and in the right places?

Many thanks.

 

DanA




msg:1265257
 7:44 pm on Jan 17, 2005 (gmt 0)

variables not used in a function will be set.
you should use
getenv("REQUEST_URI") instead of $REQUEST_URI
You must echo the variable to use it :
<?php
echo "<a HREF=\"http://mydomain.com/$my_data[2]\">Some Text</a>";
?>

calvinmicklefinger




msg:1265258
 8:49 pm on Jan 17, 2005 (gmt 0)

Many thanks. Many, many thanks.

calvinmicklefinger




msg:1265259
 9:39 pm on Jan 17, 2005 (gmt 0)

Another question - should the pages I call with the $include be .htm/html pages, or should they be .txt, or, if they are using the variables, should they be .php, which would mean nesting a .php inside a .php?

Many thanks again.

Finger




msg:1265260
 11:00 pm on Jan 17, 2005 (gmt 0)

I like to think of the include statement as a "copy and paste" operation where the code in the filename is being copied directly into the location of the include (keep in mind that the included php code still needs to be inside the <?php?>, otherwise php will treat it as text output/html). So it doesnt matter what the extension of the include file is, it uses the content of the file. However, if you use an extension that apache doesn't parse as php (like .txt for example) someone could view your code. And you could get around that by editing your .htaccess file. Hope this helps...

dmmh




msg:1265261
 3:53 am on Jan 18, 2005 (gmt 0)


Another question - should the pages I call with the $include be .htm/html pages, or should they be .txt, or, if they are using the variables, should they be .php, which would mean nesting a .php inside a .php?

stick to .PHP, by far the safest

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved