GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-May-2004, 05:39
dopee dopee is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: south africa
Posts: 109
dopee will become famous soon enough

uisng php to display php


Right so i've managed to read and display my menus of my site from a textfile, using php to dispaly the data in html format. Now I recently tried to add a poll to my one menu. This involves including an external php file. SO I enter this into my menu textfile:

PHP Code:

<?php 
$poll_show="website";
Include("poll/poll.php");
 ?>


But when I refresh my website, the contents of the textfile are display exact. Meaning when I view the source of the output of the webpage, everything is in html format, even for that php I entered into the textfile.
IE: This is what a part of the menu looks like (in html!!):
HTML Code:
<table border="0" width="100%"> <tr> <td align="center">Mywebsite Poll</td> </tr> <tr> <td align="center"> <?php $poll_show="website"; Include("poll/poll.php"); ?> </td> </tr> </table>
Why the Hell is the php not executed??!!!!!
Last edited by dsmith : 09-May-2004 at 07:33. Reason: Please use syntax highlighting when posting
  #2  
Old 09-May-2004, 08:45
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Are you still using fopen() and friends to include this textfile?
  #3  
Old 09-May-2004, 11:03
dopee dopee is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: south africa
Posts: 109
dopee will become famous soon enough
yes I do and including the text file works fine. The problem is, the php code within the textfile does not want to execute.
  #4  
Old 13-May-2004, 13:52
dopee dopee is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: south africa
Posts: 109
dopee will become famous soon enough
ANybody?

Perhaps when I store the php in the textfile, it should be stored as follows:
&lt;?php
print "this is text generated by php";
?&gt;

Will it execute then?
  #5  
Old 14-May-2004, 08:53
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Oops! Sorry Dopee, I was a bit distracted this week on some other things and I didn't mean to ignore this thread.

Anyway, my last reply should have given you a clue why it doesn't work...

So back to the issue; let's assume you had a regular web page named... say; new-1.php. Inside this PHP file you have this code:

PHP Code:

<html>
<head>
<title>Dopee's Test page: NEW-1.PHP</title>
</head>
<body>
<?php 
  // copied from your own code submitted previously in another thread
  include_once( './showmenu.php' );
?>
</body>
</html> 



Now since you're using fopen() and friends to READ in the contents of lmenu.txt, it doesn't really parse ANY PHP code inside lmenu.txt!

To fix this you can do 2 things; you could use the function eval() to parse the contents off lmenu.txt AFTER it's read in by showmenu.php OR...

just modify the example above to something like this:

PHP Code:

<html>
<head>
<title>Dopee's Test page: NEW-1.PHP</title>
</head>
<body>
<?php
// we DON'T need this now...
  //include_once( './showmenu.php' );
  include_once( './lmenu.txt' );
?>
</body>
</html> 


But remember, if that poll script is doing anything with headers and cookies, you're going to need the help of ob_start() and friends...
  #6  
Old 14-May-2004, 15:06
dopee dopee is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: south africa
Posts: 109
dopee will become famous soon enough
I see now!
So instead of opening the textfile and printing it line by line, I use the include_once(); function and the php within the textfile is executed.
Thanx man big help ill try it now.
  #7  
Old 14-May-2004, 18:40
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Looks like you finally understood what I was trying to explain. Also, note the last sentence in my last reply. If you find "headers already sent..." errors, simply insert ob_start() to the top of your web page / script (not in the include files), like in the example below and hopefully, any such errors will go away:

PHP Code:

<?php ob_start(); ?>
<html>
<head>
<title>Dopee's Test page: NEW-1.PHP</title>
</head>
<body>
<?php
// we DON'T need this now...
  //include_once( './showmenu.php' );
  include_once( './lmenu.txt' );
?>
</body>
</html>
 
 

Recent GIDBlogCompress Your Web Site by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php software dopee MySQL / PHP Forum 0 04-May-2004 11:26
Optimizing your web server with Turck MMCache for PHP JdS Web Hosting Forum 2 07-Jan-2004 07:48
Automate a data change php form mjfmn MySQL / PHP Forum 4 20-Oct-2003 09:37
[Linux] Installing PHP --with-mcrypt JdS Web Hosting Forum 0 20-Aug-2003 08:40
All the big PHP script collections that matter jrobbio MySQL / PHP Forum 5 06-Jun-2003 16:14

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:28.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.