A Digital Age Deserves A Digital Leader

read php code from file and run it

read php code from file and run it

Postby toddthegeek » Sat Jan 26, 2008 3:24 am

Hi all,

I don't know if there is a way to do this, but I would really appreciate it if you guys know of a way to do this.

I want to have some php code --lets say in index.php-- setup to read the code in another file --say code.php--. The catch is that code.php well contains some php code that i want to be ran in index.php.

Is there any way to do this? If you don't understand the questions this might help.

Index.php is my main page, and on it I want a sidebar --maybe a simple calendar and a login field (it may change on each page so I'd want one file to be linked to all pages). I put the HTML/PHP for the sidebar in a file called code.php. Index.php will read code.php and just display all the text without running the php code.

I'm fairly new at php so I don't know if there is a way to do this or perhaps a better way to accomplish what I want.

Any ideas? Thanks.
<img border="0" src="http://www.toddtoddtodd.com/pics/computer_sig_small.jpg" width="375" height="150">
PRO Level 5
User avatar
Posts: 169
Joined: Thu Nov 04, 2004 4:54 am
Location: chicago

Postby c0ldfyr3 » Sat Jan 26, 2008 3:54 am

i do believe you could use...

Code: Select all
include('code.php');
Image
PRO Level 15
User avatar
Posts: 1346
Joined: Sun May 02, 2004 8:49 pm
Location: 127.0.0.1

Postby jbullard » Sat Jan 26, 2008 8:34 am

You can use different options actually.

include continues executing code no matter what; even if an error is evaluated whereas require does not. It will actually prevent the rest of the code from running.

But it is really up to how you want errors to be handled if one is encountered.
VP - Software
User avatar
Posts: 3653
Joined: Sun Jun 06, 2004 10:17 pm
Location: Utah
Real Name: Jason Bullard

Postby toddthegeek » Sat Jan 26, 2008 10:17 pm

ah ha. i was trying to think of a complex way of solving the problem when all i needed was a simple one.

I'll give that a shot. Thanks guys!!
<img border="0" src="http://www.toddtoddtodd.com/pics/computer_sig_small.jpg" width="375" height="150">
PRO Level 5
User avatar
Posts: 169
Joined: Thu Nov 04, 2004 4:54 am
Location: chicago

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 0 guests

cron
cron