I'm not sure what the issue is, but my guess is that the $_GET variable won't read my ajax URL correctly, because of my deep linking plugin.
The final URL looks something like:
/dashboard.php#/projectSetup.php?mode=edit&getJobNumber=2012-30
HERE is my PHP:
$getJobNumber = $_GET['getJobNumber'];
$mode = $_GET["mode"];
When I echo $mode or $getJobNumber I am not getting a result. I believe the issue has to do with the format of the URL. Notice the 2 .php files and the # in the middle.
Please let me know if anyone knows of a work around.
You're exactly right. Anything following the # in a url is considered the "document fragment", and is not sent to the server.
Do a "find" for "fragment" in The URL RFC and you'll quickly see how using # in your urls for anything else is not compatible with the internet, in general.
Related
I am trying to pass some parameters after # in the url like http://developer.rohitkhatri.com/test.php#embed=sdkhfjshdkfhhjk, But I don't know how to access it, I tried many solution from the stackoverflow, here are some examples what I've tried:
$_SERVER['REQUEST_URI'] gives me /test.php
$_SERVER['QUERY_STRING'] gives empty string
$_SERVER['HTTP_REFERER'] gives empty string
also tried printing the whole $_SERVER array but I did not find anything useful.
Any help is appreciated.
Well, there's no way to achieve this, because the part you are trying to access using the php, never goes to the server, what you can do is, just grab the part using the javascript and send it the the server.
Like there can be a middle page, which will redirect to the final url, and while redirecting, It can grab the part after # and send it using ajax.
The browser doesn't send anything that comes after the hash(#) to the server because it is resolved within the browser. You can try by mentioned code.
$hash = '<script>document.write(document.location.hash)</script>';
echo $hash;
output :
//#embed=sdkhfjshdkfhhjk
I m in a situation where i am redirecting user to another page with following jQuery code
window.location = "/#/customer/email?isEmail=true&eid=1&template=2";
i have some url re-writing , and so complete url becomes is
https://demo.qa.com/#/customer/email?isEmail=true&eid=1&template=2
but in PHP when i try to get full page url using this
echo $_SERVER['REQUEST_URI'];
it just gives me this
/
i just want to get variable IsEmail
$_GET['IsEmail']
value in PHP page,
I think the
#
in between the URL is creating the problem, is there any way to get it, please advise..
The fragment is never sent to the server, so if you want access to the query parameters you need to bring them forward:
https://demo.qa.com/?isEmail=true&eid=1&template=2#/customer/email
^ ^
query fragment
The anchor fragment portion of the URL (anything after #) isn't sent to the server at all. It only lives client-side. The server has no knowledge of it, and therefore PHP has no knowledge of it.
If you want to do anything with the anchor fragment, you must do it client-side.
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).
I have a simple file I have created:
<?php echo file_get_contents("http://occupancyadvantage.com/shortquiz.aspx?sid=234"); ?>
I can only get the file to render properly when I remove the parameters (well, when you say properly, I doubt you would consider that (http://occupancyadvantage.com/processfree.php -- the %# page.... is showing up) But I could care less about that.
I'm just trying to get a php file to load this aspx file with the ?sid=243 parameter on the end of it.
I don't have access to curl - I have a few weeks without the tech guy here and I'm not allowed to make that kind of an install w/o him... I do have access to the ini file here is what it does have. If something isn't on, I don't know what it is: http://occupancyadvantage.com/phpinfo.php
I've been killing myself with this and I just can't seem to figure it out. Besides punching babies I figured this place was the best option.
If you could please, try to spell out your responses the best you can, as being vague will probably just end up with me researching and asking more questions. I appreciate it.
This note from PHP's documentation on file_get_contents() might help:
If you're opening a URI with special characters, such as spaces, you
need to encode the URI with urlencode().
So that would be:
<?php echo file_get_contents(urlencode("shortquiz.aspx?sid=234")); ?>
If that doesn't work, maybe use the full URL? As in:
<?php echo file_get_contents(urlencode("http://your-site-here/shortquiz.aspx?sid=234")); ?>
You can't file_get_contents with parameters if it's a local file. Just like you can't actually open the file with the parameters in a text file, it doesn't make sense to F_g_c.
You can, if the aspx is http-able, use f_g_c(http:/...).
Otherwise, you'll have to use wget (there are nastier ways to do it such as exec, but don't use them unless you don't need security at all).
You are trying to open the file named shortquiz.aspx?sid=234 in the current working directory. I'm guessing there is no such file in the current working directory.
If you want to fetch the url that ends with shortquiz.aspx?sid=234, you can try this:
file_get_contents('http://example.org/shortquiz.aspx?sid=234');
Of course, replace "example.org" with the full host and path for this URL.
I ended up using an iFrame to do this. I don't know what I was thinking. Thank you for all of your time.
I am asked to work with a service that changes my websites url to: http:://example.com/#/?id=9
I cannot seem to be able to get the id from such URL. $_GET is empty, $_SERVER['REQUEST_URI'] only contains /.
How am I supposed to get to the params?
Things I have tried:
Zend_Debug::dump($_GET); // outputs array(0)
echo $_SERVER['REQUEST_URI']; // outputs /
Zend_Debug::dump(parse_url($_SERVER['REQUEST_URI'])); // outputs array(["path"] => string(1) "/")
I am using Zend Framework but I doubt its something to do with it.
Thanks in advance.
You can't parse that with PHP, for the simple reason that as far as the URL concerns, anything beyond the # (hash) is not part of the URL, that part must be parsed with JavaScript or a similar client side language.
window.location.hash
Will return everything past the hash (including the # character)
In short: not possible in server, go with client. (maybe post an ajax call to a server with the GET data)
Everything including and following the # is for the browser's interest only.
The server never even sees it.