$_GET without foo - php

How can I use download.php?get=file.exe with without the get variable, like download.php?=file.exe, using the $_GET in PHP?

You can use $_GET[0] or $_REQUEST[0]

You could use $_SERVER['request_uri'] which would allow you to omit the ? completely, leaving you with URLs like example.com/download.php/file.exe
Then, with a bit of URL rewriting (or implementing a bootstrap controller) you could clean it up even more, resulting in example.com/download/file.exe

What you need i address rewritting this wikipedia article should give you enough information to stat with. Specifically, if you use apache, read about mod_rewrite.

You can use $_SERVER['QUERY_STRING'] to get everything after the ?.
Edit: Then you could use download.php?file.exe

Related

Difficulty with nginx rewrite syntax

I need to extract 3 input parameters (in this example a=test, b=sell, c=12536) from the following URL
/property-test-sell-12536
and pass to the PHP file as $_GET parameters. And inside PHP file I want to access this parameter as $_GET['a'], $_GET['b'], $_GET['c'].
I researched Google about this issue. Is it possible to use only NGINX for this purpose or should I do it inside PHP file?
Input arguments are defined as ?index=value&anotherIndex=anotherValue and so forth, for example: https://example.com/search.php?query=How+to+google&lang=en
PHP will then have the variables named as the appropriate index ($_GET['index'] will return you the value).
If you'd like to have routes like example.com/shoes/5/seller then you'd need to code a custom PHP function which trims the URL and looks for strings and then stores them in an appropriate variable, probably using a regex and preg_match. Though, be careful about security as these can be rather vulnerable to things like SQL injections and server-side code execution vulnerabilities.

How to achieve a simple re-direct to a GET request?

I have a page that does a re-direct as such, following the guidelines from this SO Post.
header("Location: http://www.fivefoo.com?uid=johnny");
die();
This small php file is located here in index.php of course.
http://www.fivefoo.com/johnny
What I did was just add on a query to the re-direct
?uid=johnny.
First and main question. Am I allowed to to do this?
Secondly, where do I retrieve the query values. My guess, would be the $_GET global.
Yes you are allowed to do this (why shouldn't you be?)
Yes, you can get the query values from the $_GET superglobal array. More specifically, $_GET['uid'] will contain the text 'johnny' (without the quotes of course).
Yes, you can do this.
Yes, the $_GET is used for this, so $_GET['uid'] in your example would return 'johnny'.
More info here

How to have detect/implement parameter passing like domain.com/parameters without '?' or any carrier variable like name=aksd

How to do that? Is it possible to do it without a framework? I'm using php.
Refer to Mod rewrite documentation
Make a rule something like,
name\.($1) webservice.php?name=$1
In webservice.php read the name parameter, and use it as you want.

How to deal with question mark in url in php single entry website

I'm dealing with two question marks in a single entry website.
I'm trying to use urlencode to handle it.
The original URL:
'search.php?query='.quote_replace(addmarks($search_results['did_you_mean'])).'&search=1'
I want to use it in the single entry website:
'index.php?page='.urlencode('search?query='.quote_replace(addmarks($search_results['did_you_mean'])).'&search=1')
It doesn't work, and I don't know if I must use urldecode and where I can use it also.
Why not just rewrite it to become
index.php?page=search&query=...
mod_rewrite will do this for you if you use the [QSA] (query string append) flag.
http://wiki.apache.org/httpd/RewriteQueryString
$_SERVER['QUERY_STRING'] will give you everything after the first "?" in a URL.
From here you can parse using "explode" or common sting functions.
Example:
http://xxx/info.php?test=1?test=2&test=3
$_SERVER['QUERY_STRING'] =>test=1?test=2&test=3
list($localURL, $remoteURL) = explode("?", $_SERVER['QUERY_STRING']);
$localURL => 'test=1'
$remoretURL =>'test=2&test=3'
Hope this helps
I would suggest you to change the logic of the server code to handle simpler query form. This way it is probably going to lead you nowhere in very near future.
Use
index.php?page=search&query=...
as your query format but do not overwrite it with mod_rewrite to your first wanted format just to satisfy your current application logic, but handle it with some better logic on the server side. Write some ifs and thens, switches and cases ... but do not try to put the logic of the application into your URLs. It will make you really awkward URLs and soon you'll see that there is no lot of space in that layer to handle all the logic you will need. :)

what is python equivalent to PHP $_SERVER?

I couldn't find out python equivalent to PHP $_SERVER.
Is there any? Or, what are the methods to bring equivalent results?
Thanks in advance.
Using mod_wsgi, which I would recommend over mod_python (long story but trust me) ... Your application is passed an environment variable such as:
def application(environ, start_response):
...
And the environment contains typical elements from $_SERVER in PHP
...
environ['REQUEST_URI'];
...
And so on.
http://www.modwsgi.org/
Good Luck
REVISION
The real correct answer is use something like Flask
You don't state it explicitly, but I assume you are using mod_python? If so, (and if you don't want to use mod_wsgi instead as suggested earlier) take a look at the documentation for the request object. It contains most of the attributes you'd find in $_SERVER.
An example, to get the full URI of the request, you'd do this:
def yourHandler(req):
querystring=req.parsed_uri[apache.URI_QUERY]
The querystring attribute will now contain the request's querystring, that is, the part after the '?'. (So, for http://www.example.com/index?this=test, querystring would be this=test)

Categories