Page 1 of 1

Characters in url being replaced.

Posted: Mon Apr 07, 2008 11:30 pm
by dman
This is probably a simple question, but I am unsure of how to fix it.

I have a page set up to take a url from a form, then send it via GET to the same page, then play the file with a shell_exec(). Here is my code:

Code: Select all

<html>
<head>
<title>Play music file</title>
</head>
<body>
<?php
$file = $_GET['file'];
if ($file == null) {
echo('<p>Please enter music file you wish to play. Allowed formats are mp3 & wav.</p><form action="play.php" method="get"><p><input type="text" name="file" /><input type="submit" value="Play" /></form>');
} else {
$command = shell_exec('mpg123 "' . $file . '"');
echo('<p>File ' . $file . ' is now playing.');
}
?>
</body>
</html>
My problem is that the url gets all special characters replaced with their equivalents for html; i.e. http:// = http%3A%2F%2F when I need http:// to be sent to the command. I can't figure out how to change it back.

When I echo the variable, it shows fine, html doing what it's supposed to do.

How can I get the correct string sent to the command?

Note: Yeah, this is probably very insecure, but this is a locally-accessible only server, so I'm not too worried.

Re: Characters in url being replaced.

Posted: Tue Apr 08, 2008 3:19 am
by Kadanis
Some characters just can't be part of a URL. I think the best way to do this would probably be to use the form POST method and $_POST for your code instead of passing the URL on the URL.

Re: Characters in url being replaced.

Posted: Tue Apr 08, 2008 11:06 am
by dman
That doesn't help, unfortunately. I believe it is still send ing it wrong; now I just can't see it to help diagnose.

Daniel