Characters in url being replaced.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dman
Forum Newbie
Posts: 2
Joined: Mon Apr 07, 2008 11:21 pm

Characters in url being replaced.

Post 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.
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Re: Characters in url being replaced.

Post 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.
dman
Forum Newbie
Posts: 2
Joined: Mon Apr 07, 2008 11:21 pm

Re: Characters in url being replaced.

Post 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
Post Reply