/    Sign up×
Community /Pin to ProfileBookmark

Can a PHP file edit itself?

I need a PHP file that can write to itself, I have a very good (and long) reason for doing this.
For example, I want test.php to open test.php and change the contents of test.php to something else.
Can I do this?

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 25.2011 — Yes, you can.
Copy linkTweet thisAlerts:
@eval_BadCode_Apr 25.2011 — Yes... consider locking the file as you write to it, and making backups.
Copy linkTweet thisAlerts:
@joe12joeApr 25.2011 — Yes it is possible. You may try this:

[code=php]<?php unlink(__FILE__); ?>
[/code]
Copy linkTweet thisAlerts:
@svidgenApr 25.2011 — I would be interested in learning the good, long reason for this.
Copy linkTweet thisAlerts:
@criterion9Apr 25.2011 — I would be interested in learning the good, long reason for this.[/QUOTE]

As would I. I'm always curious about stuff like this.
Copy linkTweet thisAlerts:
@linkskuauthorApr 25.2011 — Ummm... let's just say I got the idea from hackforums.net :o

Do I simply use fopen and fwrite?
Copy linkTweet thisAlerts:
@svidgenApr 25.2011 — I imagine you could just use file_get_contents() and file_put_contents() ...

I'm still interested to learn why you want to do this. Not so interested where the idea came from ...
Copy linkTweet thisAlerts:
@aj_nscApr 25.2011 — The OP doesn't want to say svidgen because he's obviously up to some ethically questionable business - at least that's what I gathered from the hackforums.net reference.
Copy linkTweet thisAlerts:
@rproctor83Apr 25.2011 — Developing any type of malicious code, phishing software or anything of the like is prohibited and hopefully no community member will help further the ongoing battle that we have against such unethical procedures. It's one thing to hack a script to make it do what you want, but its another to develop a hack to infringe on someones privacy, rights and or intent.
Copy linkTweet thisAlerts:
@dalecospApr 25.2011 — The OP doesn't want to say svidgen because he's obviously up to some ethically questionable business - at least that's what I gathered from the hackforums.net reference.[/QUOTE]+1. :eek:
Copy linkTweet thisAlerts:
@linkskuauthorApr 26.2011 — Nevermind then, I know discussing anything malicious isn't allowed here, I'll use Google and work on my script. The folks over at HackForums aren't good with PHP ?
Copy linkTweet thisAlerts:
@aj_nscApr 26.2011 — Shocks me why you'd even ask.....not because of the malicious intent of it, but because it takes about 1 minutes to write a script on your local server and find out the answer.
Copy linkTweet thisAlerts:
@dalecospApr 26.2011 — Shocks me why you'd even ask.....not because of the malicious intent of it, but because it takes about 1 minutes to write a script on your local server and find out the answer.[/QUOTE]And that's true, also.

I do think that sometimes we're either just tired or need some "human" interaction for some other reason, so we post in a community rather than expend the energy needed to DIY.
Copy linkTweet thisAlerts:
@aj_nscApr 26.2011 — And that's true, also.

I do think that sometimes we're either just tired or need some "human" interaction for some other reason, so we post in a community rather than expend the energy needed to DIY.[/QUOTE]


I strongly second that.
×

Success!

Help @linksku spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...