pedrwvargas Posted April 19, 2017 Share Posted April 19, 2017 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! Quote Link to comment Share on other sites More sharing options...
dkub Posted April 19, 2017 Share Posted April 19, 2017 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... 1 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 19, 2017 Share Posted April 19, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...
pedrwvargas Posted April 19, 2017 Author Share Posted April 19, 2017 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. Quote Link to comment Share on other sites More sharing options...
Solution pedrwvargas Posted April 19, 2017 Author Solution Share Posted April 19, 2017 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? Quote Link to comment Share on other sites More sharing options...
dkub Posted April 19, 2017 Share Posted April 19, 2017 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. Quote Link to comment Share on other sites More sharing options...
pedrwvargas Posted April 19, 2017 Author Share Posted April 19, 2017 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.