Jump to content

Executing php from terminal


regdude

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.