regdude Posted August 10, 2009 Share Posted August 10, 2009 Hi! I have a file in /var/www/localhost/stuff.php Then I use a command: "php /var/www/localhost/stuff.php?id=5" It fails because of special char "?", so if I use "php /var/www/localhost/stuff.php" - it works! With how I must replace "?" to make it work? Quote Link to comment https://forums.phpfreaks.com/topic/169649-executing-php-from-terminal/ Share on other sites More sharing options...
rlelek Posted August 11, 2009 Share Posted August 11, 2009 Hello, You are trying to use something called "$_GET variables" or variables that are passed via the URL (or URI). $_GET is a cousin of $_POST and the fact is, these methods were both made for HTTP servers, not a terminal/shell or the PHP process itself (which gets executed when you type "php pilename.php" at the command line). How would you go around this? Unless you have a very specific reason for doing it from the command line, which I can't think of very many, I would suggest downloading a server stack that corresponds to your setup like these: LAMP - Linux Apache MySQL PHP WAMP - Windows Apache MySQL PHP MAMP - Macintosh Apache MySQL PHP just google the name and you'll find some downloads. There are other ways to set up a stack without these packages, but the packages, while less customizable because they use default settings to install, are by far the easiest way to do it. Most of the time, the defaults are perfect for a development environment (testing), but should be glanced over before being put into a production environment (live). There is a workaround...but I'd use the above method http://bytes.com/topic/php/answers/491693-passing-_post-variables-command-line-php Hopefully this helps you out Ryan Quote Link to comment https://forums.phpfreaks.com/topic/169649-executing-php-from-terminal/#findComment-895362 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.