Jump to content

Half of my code doesn't work


pedrwvargas

Recommended Posts

Here's my code:

<?php
$new = $_GET['new'];
$del = $_GET['del'];
if (is_null($new)  ) {
    exit;
}
else {
    if (file_exists($new)) {
        header('Location: ../# the file '.$new.' '.'already exists in /docs/');
    }
    else {
        fopen($new, 'w');
    }
}

if (is_null($del)  ) {
    exit;
}
else {
    if (file_exists($del)) {
        unlink($del);
    }
    else {
        header('Location: ../# the file '.$del.' '.'does not exist in /docs/ so it cannot be deleted');
    }
}
?>

It works to perfection from line 1 to 15. It doesn't from line 16 to 27 though.

No errors or warning given when executing it.

 

I can tell I kind of messed up writing an if statement after another one but I couldn't figure our a way to merge them. Also adding endif; at the end of each if statement would result in error.

 

What can I do about it?

 

Thanks in advance!

Link to comment
Share on other sites

Oy vey. Did you read what I told you about malware? Now you've made it even worse.

 

You need to stop typing random code on your keyboard and actually think about what you want to do. Why do you store files at all? If you want to save text, use a database.

Link to comment
Share on other sites

Oy vey. Did you read what I told you about malware? Now you've made it even worse.

 

You need to stop typing random code on your keyboard and actually think about what you want to do. Why do you store files at all? If you want to save text, use a database.

 

Nobody is gonna use it but me, I'll password protect it (even encrypt it in a further future? haha), and it's just for learning. What I'm trying to do is a kind of "terminal" on my navigation bar.

Link to comment
Share on other sites

Are $_GET['new'] and $_GET['del'] both going to be set at the same time? If $_GET['new'] is null, you exit, never getting to evaluate other conditions...

Thanks, I've been wondering that for a while, you confirmed it. Should I leave it blank instead?

Link to comment
Share on other sites

Should you leave what blank? It's not clear what you're even trying to accomplish here. You create a file resource but don't use it, you delete files and then do nothing. And, of course, you leave yourself open to directory traversal attacks.

Link to comment
Share on other sites

Should you leave what blank? It's not clear what you're even trying to accomplish here. You create a file resource but don't use it, you delete files and then do nothing. And, of course, you leave yourself open to directory traversal attacks.

-Do nothing (so far).

-It's not clear, I know. Difficult to explain. I'll show you guys when it's done though. I'll make a copy of it.

-Traversal attacks. I'll work on that later. I guess you can do something about it, right?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.