I got this URL:
http://twitternieuws.com/class/function/ID?oauth_token=xxxxx&oauth_verifier=xxxxx
And I keep getting errors like "The page you requested was not found" or "The URI you submitted has disallowed characters". I tried changing the following options with different settings:
$config['permitted_uri_chars'];
$config['enable_query_strings'];
$config['uri_protocol'];
Is there anything I can do to make it work? I am using codeigniter 1.7.2
Query strings in 1.7.2 are a joke, it uses ?c=controller&m=method to basically change your pretty urls to psuedo $_GET params. I really can't see why anyone would use it the way it's intended, it's very misleading and is not the same as normal query strings.
I highly suggest you check out the latest version of Codeigniter, where they do not unset the $_GET array (normal query strings are now usable). In one of the core files in the older versions it says CI does not use $_GET so we are going to unset() the global $_GET array. Well, what if I need to use $GET? I always thought it was crazy, and people have been screaming for true $_GET support for forever.
Seriously though, it's time to upgrade:
Latest: https://bitbucket.org/ellislab/codeigniter-reactor/
Stable: http://codeigniter.com/
When upgrading to CodeIgniter 2 is not an option, you can recreate the $_GET variable like so (add this to every controller where you need the query string):
parse_str($_SERVER['QUERY_STRING'],$_GET);
And change this in your config.php file:
// $config['uri_protocol'] = "AUTO"; // change from this
$config['uri_protocol'] = "PATH_INFO"; // to this
Related
I have the following code in first page:
$_SESSION['redirect_address'] = $_SERVER['REQUEST_URI'];
when I call $_SESSION['redirect_address'] in the next page it gives me something like this:
/host/example.php?1508270070
while it must give me someting like:
/host/example.php?url=XYZ
When I check the value of $_SESSION['redirect_address'] at the very end code of the first page it gives me the correct value, while checking the same $_SESSION['redirect_address'] at the very beginning of the code of the second page it returns the numbers, tried to clear cookies with no luck.
Spent on this 4 hours over the net, and no one could answer my question, please help!
Your NGINX is doing something it probably shouldn't
...but that's what it is currently configured to do
According to RFC3986, the full path and "query-string" should be included in the URI.
According to PHP $_SERVER documentation, $_SERVER('REQUEST_URI') does not neccessarily include the query-string. Various server configurations and php versions have very different results regarding what data is stored in this variable, if any.
Check your environment
Based on your existing environment's configuration, you should probably check what values you are actually getting for the following SERVER variables: QUERY_STRING, ORIG_PATH_INFO, PATH_INFO, PATH_TRANSLATED, SCRIPT_NAME, REQUEST_URI, and PHP_SELF.
Adjust your session redirect accordingly.
I'm kind of a noob at this stuff.
But I've been browsing around and I see sites that are kind alike this
www.store.com/product.php?id=123
this is really cool. but How do I do it?
Im stuck using something like this
www.store.com/product/product123.php
If you could tell me how I can go about do this it would be awesome!
What you're looking at is a $_GET argument.
In your PHP code, try writing something like this:
$value = $_GET['foo'];
Then open your page like this:
hello.php?foo=123
This will set $value to 123.
You need to use the $_GET here.
if you use the following:
?id=123
then this will be how to use it and the result
$_GET['id'] (returns the 123)
You can use as many $_GET arguments as you need, for example:
?id=123&foo=bar&type=product
$_GET is an array of what parameters are in the url, so you use it the same way as an array.
Create a file called product.php with this code:
<?php
echo "The argument you passed was: " . $_GET['id'];
?>
Now run this URL in your browser:
http://<yourdomain>/product.php?id=123
and you will understand how $_GET works.
Those are called URL parameters (what they're contained in is called a query string), and they're not unique to PHP but can be accessed in PHP using the $_GET superglobal.
Similarly, you can get POST parameters using the $_POST superglobal, though in POST requests, these parameters are not appended to the URL.
Note: Generally, for usability purposes (and thus also SEO purposes), you want to avoid using query strings as much as possible. These days, the standard practice is to use URL rewriting to display friendly URLs to the user. So your application might accept a URL like:
/products.php?id=32
But the user only sees:
/product/32
You can do this by using mod_rewrite or similar URL rewriting capabilities to turn the friendly URL into the former query string URL internally, without having the user type out the query string.
You might want to have a look at the documentation at www.php.net, especially these pages: http://www.php.net/manual/en/reserved.variables.php
Specifically, have a look at $_GET and $_POST, which are two frequently used ways to transmit information from a browser to the server. (In short, GET-parameters are specified in the URL, as in your question, while POST-parameters are "hidden from view", but can contain more data - typically the contents of forms etc, such as the textbox you posted your question in).
In my projects i often use get params as a temporary way to test things with different values.
However it seems like you cannot access get params in code igniter?
I am aware I could build a param into my functions and pass the value as a url segment.
But i dont want to be doing that every time I wish to test something.
So,
is there any way to use get values in CI?
You can parse $_SERVER['QUERY_STRING'] and set it as $_GET:
parse_str($_SERVER['QUERY_STRING'], $_GET);
You can enable query strings in your config file. Find this.
$config['enable_query_strings'] = FALSE;
and change it to true.
I've been doing PHP for a while now, never needed assistance, but totally confused this time. I have a single line of code with one echo statement.
Problem: URL parameters are automatically assuming PHP variable values of the same name. For example, I have a URL with a parameter named var_name like this:
http://www.example.com?var_name=abc123
and a 1-line PHP script with a variable named var_name, like this:
echo $var_name;
then I get output on the page of: abc123
This is the only code in the PHP page! This behavior is exactly how I expect $_GET to work, but I'm not using it.
I am having this problem only on 1 specific server, which is running PHP 5.2. I have tested on 4 other servers, none have this behavior. I assume it's a PHP config issue, but running default config and can't find anything in config documentation.
This is called register globals. If a server has register globals turned on, then you can do this.
I would recommend not to have register globals on any server. Since it can introduce a security flaw in your system.
An example of a security flaw with this.
if($auth == true)
{
// sensitive stuff here
}
If auth is just a regular variable, then I can do this in the URL.
http://www.example.com/page.php?auth=true
And see the sensitive information.
You probably have register_globals enabled:
See the manual for info.
I'm trying to make a bookmarklet that will take the URL of the current page you are on, and send it to an application written using CodeIgniter.
The problem I keep running into is that I can't do a standard AJAX call, because it's cross-domain. It is disallowed, and I can't figure out a way to use the JSONP via $_GET method since CodeIgniter blows away the $_GET parameter.
At this point I'll take any suggestions on how to do this. Please note that I need to send a URL, and if it's to be passed via a URL itself it obviously needs to be encoded or something. This I also haven't figured out how to do, so any pointers on that end would be appreciated as well.
Codeigniter unsets $_GET but you can get the data from the query string. It is a little inefficient because PHP will probably end parsing the query string twice, but it should work:
parse_str($_SERVER['QUERY_STRING'], $get);
print_r($get);
All the GET variables should be accesible in the variable $get. See parse_str() documentation for some more information.
As an alternative you could url-encode the current URL and append it to what you are requesting e.g.
var url = 'http://example.com/bookmarklet/'
+ encodeURIComponent(window.location);
Then in Codeigniter do something like:
//you might have to call urldecode() on this value
$url = $this->uri->segment(0);
but you may find you then have this problem
It is possible to enable query strings in Codeigniter, but watch out for the caveats - you can't use the URL helper, for example.