Jump to content

Half of my code doesn't work


pedrwvargas
Go to solution Solved by 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.

 

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.