0

I have a PHP page that does a couple of different things depending on what action is set to in the GET data. Depending, it is supposed to return some JSON, but instead of doing anything it is supposed to it returns the bottom half of the code document itself, starting in the middle of the line. Heres the snippit from where it starts:

...
} elseif ($_GET['action'] == 'addtop') {
    if (!isset($_GET['pname']) || !isset($_GET['url']) || !isset($_GET['artist']) || !isset($_GET['album']) || !isset($_GET['file'])) {
        die('Error: Incomplete data!');
    }
    if (!file_exists($_GET['pname'].".txt")) {
        die('Error: No such playlist!');
    }
    $plist = json_decode(file_get_contents($_GET['pname'].".txt"), true);
    $fh = fopen($_GET['pname'].".txt", 'w') or die('Could not open playlist!');
    array_push($plist, array("artist" => $_GET['artist'], "album" => $_GET['album'], "file" => $_GET['file'], "url" => $_GET['url']));
    fwrite($fh,json_encode($plist));
} elseif ($_GET['action'] == 'delfromp') {
...

And here is what I get when I go to the page:

$_GET['artist'], "album" => $_GET['album'], "file" => $_GET['file'], "url" => $_GET['url'])); fwrite($fh,json_encode($plist)); } elseif ($_GET['action'] == 'delfromp') { if (!isset($_GET['pname']) || !isset($_GET['id'])) { die('Error: Incomplete data!'); } if (!file_exists($_GET['pname'].".txt")) { die('Error: No such playlist!'); } $plist = json_decode(file_get_contents($_GET['pname'].".txt"), true); $fh = fopen($_GET['pname'].".txt", 'w') or die('Could not open playlist!'); unset($plist[$_GET['id']]); $plist = array_values($plist); fwrite($fh,json_encode($plist)); } elseif ($_GET['action'] == 'readp') { if (!file_exists($_GET['pname'].".txt")) { die('Error: No such playlist!'); } $plist = json_decode(file_get_contents($_GET['pname'].".txt"), true); $arr = array("entries" => $plist); $json = json_encode($arr); echo $json; } elseif ($_GET['action'] == 'getps') { $plists = array(); if ($handle = opendir('Playlists')) { while (false !== ($playlist = readdir($handle))) { if ($playlist != "." && $playlist != "..") { array_push($plists, substr($playlist, 0, strripos($playlist, '.')-1)); } } } else { die('Error: Can\'T open playlists!'); } $arr = array("entries"=>$plists); $json = json_encode($arr); echo $json; } else { die('Error: No such action!'); } ?>

It starts in the middle of the array_push(... line.

I really can't think of what it is doing. Theres no echos anywhere around it. Any ideas?

1 Answer 1

3

Looks like => is closing your PHP code. Do you have short tags enabled? Or some sort of custom tags?

Sign up to request clarification or add additional context in comments.

1 Comment

Ah. that was kind of weird. I had started it with a short tag, so i changed it to the regular tag and it fixed it. Though I'm not sure why it would start printing the code in the middle...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.