Server doesn't recognize file with GET - php

I have a problem with server and too upset and don't know what to do, never met such problem.
The index2.php file is ok and working, but when I add $_GET it doesn't find the file.
For example index2.php works, but index2.php&p=1 doesn't work or index2.php&t=2 or any &, doesn't work.
It says:
Not Found
The requested URL /index2.php&p=2 was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
Does anybody know what's going on?

try index2.php?p=1 i.e whenever you are using query string to pass parameters use ? mark and if you are passing more than one parameter then use & operator to pass multiple parameters.

Related

Unable to get query parameters from laravel url get request

this is my url and i am unable to get the query parameters i dont know why.
anyone can tell me whats going on?
http://localhost:8000/senders/verify#/activate?user=qaisar72477247#email.com&option=AccountActivated
if I use
http://localhost:8000/senders/verify?user=qaisar72477247#email.com&option=AccountActivated
I can successfully get the varaibles but after putting #/activate i can't. i dont know why.
Because paths are not the same. So your route file cannot run from same line.
for this
http://localhost:8000/senders/verify#/activate?user=qaisar72477247#email.com&option=AccountActivated
First part => senders
Second part => verify#
Third part => activate
And these are the params => user=qaisar72477247#email.com&option=AccountActivated
For this one:
http://localhost:8000/senders/verify? user=qaisar72477247#email.com&option=AccountActivated
First part => senders
Second part => verify
Params => user=qaisar72477247#email.com&option=AccountActivated
didnt have the third part.
The issue is the order of the URL. The # is an anchor or fragment component, and is the last part of the URL. The query string should come before the fragment component, as anything after that will be ignored.
scheme:[//authority]path[?query][#fragment]
src: https://en.wikipedia.org/wiki/URL#Syntax
I'm guessing you're using some sort of framework such as Vue, Angular, or React, which means anything after the # is actually handled by that, and is not passed to Laravel. You'll need to manage the request with whichever framework you're using.
If you want to get the value after the hash mark (#) as shown in a user's browser: This isn't possible with "standard" HTTP as this value is never sent to the server (hence it won't be available in $_SERVER["REQUEST_URI"] or similar predefined variables). You would need some sort of JavaScript magic on the client side, e.g. to include this value as a POST parameter.
So when you call :
localhost:8000/senders/verify#/activate?user=qaisar72477247#email.com&option=AccountActivated
Your server get this :
localhost:8000/senders/verify
The browser delete everything from the hash (#) of your url, then it pass to the server http process

Passing PHP URL variables leads to Page Not Found

I have an image that is supposed to redirect to another page when it's clicked. It also "sends" two variables to the page, s and n.
echo "<a href='../?change-preference&s=up&n=".$element."'>
<img src='..media/images/sort-up.png'>
</a>";
On the change-preference page I get the two variables like so:
$s=$_REQUEST['s'];
$n=$_REQUEST['n'];
My problem is that I get a "Page Not Found" error.
Also, if I try to directly access the page it works, but only if I type this:
www.example.com/preference/change-preference
and not if I try it with :
www.example.com/preference/change-preference&s=up&n=999
Any help would be appreciated!
You should use:
www.example.com/preference/change-preference?s=up&n=999
The ? is being used in the incorrect place when you are building your link.
You need to build your link as follows:
$element = 900;
echo "<a href='../change-preference?s=up&n=" . $element ."'><img src='..media/images/sort-up.png'></a>";
This will give you:
www.example.com/preference/change-preference?s=up&n=900
And in the following link from your question the ? is missing, which will not work:
www.example.com/preference/change-preference&s=up&n=999
First you are using ? in the incorrect place as Daniel_ZA pointed out or you have typed incorrectly on your question the url that actually works. For this answer I will assume that it is the first case.
Second, do you have a php file named "change-preferences" without the .php extension? It is being parsed via php. I think probably not. So you should have a folder named change-preferences then and a file named index.php inside it right?
Well, that's the reason change-preference?s=up&n=900 redirects to change-preference\?s=up&n=900. Because you are accessing the index file for that address and not directly a file. It should work fine however.
If it still return a 404 (Page not Found) error then it's probably something that you haven't include in your question that isn't well configured or is having a bad behavior. Please try a simpler setup (create a new folder with only the minimal necessary to execute the url) or provide more information on your question.
Well.. I didn't mention that I am working with Wordpress because I thought this was 100% PHP question. It appears that "s" is a reserved term in Wordpress causing a 404 error. Changing the "s" fixed the problem. I am living this answer here in case that some one else working on Wordpress finds him/her self in the same position. Al of the reserved terms.

How to access url after # in php

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

Error with a "returnUrl" in URL params

I am working with the Yii Framework.
In a controller, after a model save, I'm trying to redirect the user to /module/controller/action and set a parameter (redirectUrl) to another URL. Here is my code:
$this->redirect(array('/module/controller/action/', 'redirectUrl'=>'/index.php/some/url/id/'.$id));
This seems to work well as I am redirected to:
http://localhost/index.php/module/controller/action/redirectUrl/%2Findex.php%2Fsome%2Furl%2Fid%2F11
But when I get there I get the following error:
Not Found
The requested URL
/index.php/module/controller/action/redirectUrl//index.php/some/url/id/11 was not found on this server.
The URL like /index.php/module/controller/action/redirectUrl/1234 works fine.
I don't understand what I am doing wrong here, URL seems to be correctly encoded. Any idea would be of great help!
Thanks
Your example URL is only passing 1234 as the parameter, not a full relative URL, e.g. /index.php/some/url/id/1234. I think what you want is:
$this->redirect(array('/module/controller/action/', 'redirectUrl'=>$id));
You could skip the URL rules on your server and minimally reduce load with:
$this->redirect('/module/controller/action/redirectUrl/' . $id);
$this->redirect($this->createUrl('/module/controller/action/',
array('redirectUrl'=>'/index.php/some/url/id/'.$id));
If this does not work do
$this->redirect($this->createUrl('/module/controller/action/',
array('redirectUrl'=>$id));
and then just add '/index.php/some/url/id/' in the action.
http://www.yiiframework.com/doc/api/1.1/CController#createUrl-detail

I get a 403 error when submitting "http://www." via GET. Even if it's encoded beforehand. Is there a solution for this?

It seems like my shared host provider is detecting the presence of "http://www" or "http%3A%2F%2Fwww" in any get request and serving up a 403 page.
I also get an 'in addition' error...
"Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."
This only happens with this string. If I change it to something else the get is successfully submitted and the target page successfully returned.
If it helps I'm writing a QR code getter, so the ability to submit urls is quite important.
Also, strangely I can submit a url as long as it doesn't have 'www' in it. I can also submit 'www' as long as it isn't preceded by 'http://' (or the encoded version)
edit: Just to confirm this wasn't a specific problem with the page I was writing, I went to another page on my website that uses get request and manually inserted the string. This also generates the 403 error.
Yes -- there are two solutions:
Request to remove this strange security feature for your account from your provider.
Don't send urls with http://www in them. For example replace this scting in javascript before sending data to some "%htpwwwashere:(%", that will be replaced by you back in PHP.
Replace any instances of http://www. with StackOverflowRulez and in your PHP have it replace the $_GET StackOverflowRulez with http://www..

Categories