Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2824
  • Last Modified:

passing argument to PHP script

myScript.php?arg is the conventional way to pass an argument to a script.  Is there a way to do it without the ? (question mark)

Any tutorials anywhere about all the different ways to treat php arguments?
0
anocean
Asked:
anocean
  • 5
  • 4
  • 2
  • +2
1 Solution
 
ykf2000Commented:
Hi,


There 4 ways to do it:

1) In the query string as in yourScript.php?arg=1

2) By submitting a form <input type="hidden" name="arg" value="1">

3) By a cookie as in setcookie("arg","1");

4) By using a session variable
   $arg = 1;
   session_register("arg");


To access the variables:

1) Use $PHP_GET_VARS["arg"] or simply $arg for method 1.

2) Use $PHP_POST_VARS["arg"] or simply $arg for method 2.

3) Use $PHP_COOKIE_VARS["arg"] or simply $arg for method 3.

4) Use $arg for session


Note that if you have variables of the same name coming from different method it is better to fully qualify it with the proper way.
0
 
anoceanAuthor Commented:
I appreciate the trouble you went to but it didn't really answer the question, which is specifically about the format for a script URL.

Is there any way around having to use the question mark (?) immediately after .php suffix?
And is there a tutorial specifically about URL syntax for scripts?
0
 
ykf2000Commented:
I do not think there is a way for you to do that without a ? behind. The  ? is used to differentiate the URL and the arguments passed. Without the ? there is no way to do that. :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
anoceanAuthor Commented:
Yeah, that's kind of what I expected to hear.  Nevertheless, I'm going to leave the question open for a couple days, but will not forget to award the points if no further answers appear.
0
 
juan_tangaCommented:
you can use the "/" instead of "?" in storing the args values...  well here's an example of it.

ex.

myScript.php/value1/value2/value3/

and this args are store in "PATH_INFO" environment var.
PATH_INFO = /value1/value2/value3/

to access each value, you need to split the values by "/"
$value_array = explode("/",$PATH_INFO);
$value_1 = $value_array[1];
$value_2 = $value_array[2];
$value_2 = $value_array[3];

hope this will help. :o)








0
 
anoceanAuthor Commented:
juan tanga, your idea sounds positively spicy, but it doesn't work straight out of the box, cuz I get CGI error.
You finish this one and I'm giving you 100 point tip.
0
 
juan_tangaCommented:
may i know what error u get?
0
 
anoceanAuthor Commented:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

It's cuz I try URL index.php/eee/555/
and that directory, of course, doesn't exist.
0
 
juan_tangaCommented:
oops...

so u're using a cgi-module of php perhaps... I tried that one using a api-module of php and i have not test it using cgi-module version of php...
0
 
juan_tangaCommented:
try printing the value of PATH_INFO... and see if the parameter store in that environment variable..

ex. echo $PATH_INFO or echo $GLOBALS["PATH_INFO"]
0
 
curriCommented:
I think ykf200 is correct (and the answer was very complete). However, depending on your webserver, you can cheat :)

If you're using Apache, you can make it rewrite the url, I think with general regular expressions, so you can write one url and let the server transform it into one with the ? :). I assume you can do that with other servers too.

A funny example of that is the isgay.com web site. Go say to john.doe.isGay.com (exercise caution, you may find it ofensive).

Orlando
0
 
higijjCommented:
you can try and read about the rewrite module for apache..

I think it can do what you waht to.
0
 
anoceanAuthor Commented:
very imaginative.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now