PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
m0u53m4t
Forum Contributor
Posts: 101 Joined: Wed Apr 19, 2006 7:47 am
Location: Wales
Post
by m0u53m4t » Wed Jun 14, 2006 4:47 pm
This is my code
Code: Select all
<?php
$serial = $_GET["serial"];
$data = file_get_contents("keys.php");
$elements = explode(',', $data);
if(in_array($serial,$elements)){
echo "Well done!";
}else{
echo "You stuffed it...";
}
?>
But I want it to delete the correct serial from the file "keys.php" once its done. how could I do that?
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Wed Jun 14, 2006 9:37 pm
Besides the fact that keys.php is probably not a valid PHP file, you could hack something out like this:
Code: Select all
// continuing inside "Well done!"
$key = array_search($serial, $elements);
array_splice($elements, $key, 1); // modifies array
$new_file_contents = implode(',', $elements);
file_put_contents('keys.php', $new_file_contents); //if you use PHP 5
Although I
seriously recommend using a database at this point.
m0u53m4t
Forum Contributor
Posts: 101 Joined: Wed Apr 19, 2006 7:47 am
Location: Wales
Post
by m0u53m4t » Thu Jun 15, 2006 10:40 am
I'm getting this error:
Fatal error: Call to undefined function: file_put_contents() in /home/freehost/t35.com/j/u/juniorfiles/rssupreme/reg.php on line 13
What can I do?
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Thu Jun 15, 2006 12:58 pm
Yep, PHP5. Substitute that with:
Code: Select all
$fh = fopen('keys.php', 'w');
fwrite($fh, $new_file_contents);
fclose($fh);
m0u53m4t
Forum Contributor
Posts: 101 Joined: Wed Apr 19, 2006 7:47 am
Location: Wales
Post
by m0u53m4t » Sun Jun 18, 2006 12:47 pm
That works. Thanks. This is some php code I have:
Code: Select all
<?php
$filename = "time.php";
$hours = $_GET["hours"]
if $hours > 24 then {
if $hours > 48 then {
if $hours > 72 then {
$days = 3;
$hours = $hours - 72;
}
$days = 2;
$hours = $hours - 48;
}
$days = 1;
$hours = $hours - 24;
}
and I want it to write $days and $hours to the file time.php in this format: " $days:$hour ". How can I do that?
m0u53m4t
Forum Contributor
Posts: 101 Joined: Wed Apr 19, 2006 7:47 am
Location: Wales
Post
by m0u53m4t » Sun Jun 18, 2006 1:32 pm
Not like that. I want it to manually write a file with figures like "1:0" to be read by some other php.