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:
  #1  
Old December 24th, 2003, 06:55 PM
mwichmann4 mwichmann4 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 81 mwichmann4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 27 sec
Reputation Power: 6
writting php tags into a file

hey again everyone,

I am trying to do some auto php code writting to a file that the user uploads. I can get the code in fine, but i can't see to get it between the <? ?> tags or even <?php ?> tags. What can i do so the code i write can be between those tags. If i can't get it to do that then when i turn the file into a .php file that code won't execute. Any help would be great. THANKS
__________________
Nothing is Everything

Reply With Quote
  #2  
Old December 24th, 2003, 09:54 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
i would say before you write anything to the file include the tags like this

PHP Code:
 $name="<?".$name."?>" 
this is similar to what i did if i wanted to higlihgt code on the forums i created give it a try...save it as this then send it to the file

Reply With Quote
  #3  
Old December 25th, 2003, 01:42 PM
mwichmann4 mwichmann4 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 81 mwichmann4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 27 sec
Reputation Power: 6
still not working right. the right ?> tag comes in but the left one does not along with some php code in the center. There has to be a way to do this. Anyone else have any other ideas?

Reply With Quote
  #4  
Old December 25th, 2003, 08:42 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
let me see your code

Reply With Quote
  #5  
Old December 25th, 2003, 10:03 PM
mwichmann4 mwichmann4 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 81 mwichmann4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 27 sec
Reputation Power: 6
LOL, I deleted it cuz i was getting mad at it. Below is the gest of what i was trying to do.


$fp = fopen("file.php","w+");

fwrite("<? $objCart->addCart;?>",1024);
fclose($fp);

That is the very simple version i had way more but like i said i deleted it. Basically all i want to do is write some php code to a new .php file. The function with a dollar sign goes in ok along with the end tag but the first tag will not write. Actually i had now luck in writting it to the file at all. OK hope that helps.

Reply With Quote
  #6  
Old December 26th, 2003, 12:36 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
unless i'm misinterpretting your question, its general discouraged to create PHP files on the fly like that...

what's stopping someone from putting malicious code in a file and running that?

are you still trying to accomplish this, or have you given up and chosen a different method?

Reply With Quote
  #7  
Old December 26th, 2003, 09:06 AM
mwichmann4 mwichmann4 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 81 mwichmann4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 27 sec
Reputation Power: 6
yup i am still trying to figure it out.

Reply With Quote
  #8  
Old December 26th, 2003, 11:21 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
PHP Code:
<?php
        $myFile 
fopen("data.php","w");
        
        if(!(
$myFile))
        {
            print(
"file could not be opened");
            exit;
        }
        
fwrite($myFile"<? echo 'hello'; ?>");
        
fclose($myFile);
?>


something like that should do the trick but i donno if u want to make the files as your going along or if you have the files already made..i tested this and it does work...=] hope this helps

Reply With Quote
  #9  
Old December 26th, 2003, 11:27 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
i think the file would be created on the fly if necessary just give data.php a variable name that your site creates..then it will automatically create the page

Reply With Quote
  #10  
Old December 27th, 2003, 12:07 AM
Mike_r Mike_r is offline
ExoCrew
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 68 Mike_r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
How are you trying to create the php file ?

If possible can you give us the whole script and it would be much better

to use variables always use single quotes (') instead of double quotes (")

example:

fwrite ( $handler, '<?php' . 'echo $this->do; ' . '?>' );
__________________
ExoHelpDesk
ExoCrew Free Services

Reply With Quote
  #11  
Old December 27th, 2003, 09:35 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
the w in the fopen automatically creates the file if does not exist. So all you have to do is create a variable that has what the file name will be. and for the line youve just gave me, it should be

PHP Code:
<? fwrite $handler"<?php echo '$this->do'; ?>" ); ?>
the reason why you need two separate quotes is because one is for the line you input and echo requires quatations too, but they cannot be the same as the line your inputting, i think thats why, give it a try let me know if it works, i see you have a class there thats why i dont know what your going to input.

Reply With Quote
  #12  
Old December 29th, 2003, 07:30 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
I'm on board with MadCowDzz -- you have to be really careful about allowing people to write PHP to your site. What's to keep somebody from sending "unlink('/etc/passwd')" as their input and then loading the page you're writing?

Reply With Quote
  #13  
Old December 29th, 2003, 04:15 PM
Mike_r Mike_r is offline
ExoCrew
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 68 Mike_r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I guess unlink('/etc/passwd'); wont work with most of the hosts as nowadays most of the host take care of their security either by installing a good control panel or using chkroot() ...


But still, its better to be safe.

Reply With Quote
  #14  
Old December 30th, 2003, 08:07 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
Heh, true, Mike_r, but you never know. With all the nickel and dime providers nowadays... How'sabout unlink($PHP_SELF) as an alternative?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > writting php tags into a 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 |