SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old December 8th, 2003, 08:09 PM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 116 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 49 sec
Reputation Power: 5
create and write php file

hi guys,

I am wondering is it possible to create a php file and write the php file we created by using php code ?? Is there any function or code that let us do this ??

I seen some people perform such tasks in their web application but i dunno how to do it ..

please advise.

Reply With Quote
  #2  
Old December 9th, 2003, 04:58 AM
hagur hagur is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Iceland
Posts: 11 hagur User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You want to use PHP to create a file, in this case a .php file which includes PHP-code?

Do I understand you correctly?

Ofcourse you can do that. You can use PHP's file functions to create almost any kind of file with whatever content suits you.

You can easily create a file with the .php extension and write PHP code to it.

<?php
$filename = 'helloworld.php';
$content = '
<?php
echo "Hello world!";
?>
';

if (!$handle = fopen($filename, 'w')) {
print "Cannot open file ($filename)";
exit;
}

if (!fwrite($handle, $content)) {
print "Cannot write to file ($filename)";
exit;
}

fclose($handle);
?>

Reply With Quote
  #3  
Old December 9th, 2003, 11:09 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Um, but I'd be very careful about doing that. For example, if you're hoping to allow users to add code to the site, you'll need to keep them from being able to add things like the following:

PHP Code:
 exec('rm /etc/passwd'); 

Reply With Quote
  #4  
Old December 9th, 2003, 11:14 AM
hagur hagur is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Iceland
Posts: 11 hagur User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
dhouston: You are right.

When allowing things like these, you must take proper security precautions.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > create and write php file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway