object not found $_GET - php

i'm trying to learn PHP but for some reason i am getting this weird issue (i am using XAMPP):
i have a simple code
<?php
echo $_GET['name'];
?>
and when ever i type http://localhost/lee.phpi get undefined index like i am supposed to, but when i type http://localhost/lee.php&name=lee i get an Object not found The requested URL was not found on this server error.
does anybody know why is this happening? is it my code or my pc maybe?

http://localhost/lee.php&name=lee
Is an incorrect URL altogether, it should be
http://localhost/lee.php?name=lee
^
Now if you were to add a new parameter you would use an & only then. First one always comes after an ?, for example
http://localhost/lee.php?name=lee&age=20
I was going to refer you to HTTP Specifications documents but since you mentioned you are learning PHP i thought that might be too overwhelming for you.
And your code is fine.
Free Tip since you said you just started learning:
Always read into error messages and believe in what they say while you are investigating an issue, they are there really for a purpose. For example
The requested URL was not found on this server error.
That error message would mean that the URL is not there on the server, if i was you i would care less about my code at that point and more about what is the reason that URL is not there when my file is there? And that would have lead me to the conclusion that the URL format is wrong.
A lot of people overlook error messages even in their advanced learning stages and say no I have everything fine and the error message is weird, no it's not.

Related

Why is PHP adding whitespace to PRINT output?

I'm having a problem with PHP that I cannot find the answer to:
I'm using PHP5.5 and Flash AS3.
I have a controlfile.php which I list the db connection info in.
When I connect via the Flash AS3 login screen, and if all is good, I expect the reply from the PHP file to be returnMsg=1 and indeed that is exactly what I get when I check with Charles 3.8.3. and the FLash Movie advances nicely
However, and this is where it starts getting weird, I have now moved my db connection lines from the controlfile.php and placed them in a connect.php. In the controlfile I have added the line require_once("connect.php");
I ran the same scenario and my Flash movie does not progress beyond the login screen as it should. I checked via Charles proxy and was indeed still getting the returnMsg=1 from the controlfile.php. Confused I checked the flash movie and put a trace on the event.target.data - it returned %20returnMsg=1. I looked back at Charles and sure enough, although I didn't notice at first, there was a blank space.
My question is What is causing this space to suddenly manifest itself when I use a require_once. As a beginner to PHP none of this makes any sense. as a work around I can ask the controlfile.php to print returnMsg=1&returnMsg=1 and the output Charles is <space>returnMsg=1&returnMsg=1. If the Flash trace it appears as %20returnMsg=1&returnMsg=1 and therefore, beacuse its is actually getting the returnMsg=1 (without the %20) the movie will progress. Sorry for the lengthy question but this is driving me completely nuts... Someone, please help with this PHP thing

Protocol Host showing in our Error Log / 404 Errors

I'm getting an error showing up in my error logs over and over. I see it in an error log in cpanel as well as in an AW stats report.
The errors look like this:
/my_directory/'%20+%20protocol_host%20+%20'/images/greenthumb.png
/my_directory/'%20+%20protocol_host%20+%20'/images/imgsicon.png
I'm seeing this thousands of times a day.
the legit path in the example above would be something like this:
/my_directory/page.php?id=123454
(i.e www.my_site.com/my_directory/page.php?id=123454)
Any ideas what this protocol_host is referring to and why it would be hitting my error log so often?
My research before posting this question led me to something related to the search indexer on a windows operating system computer, but I can't see the connection.
Thanks in advance as always
I'm with #Shal. Although google gives you some results for 'protocol_host' I don't think that they are related to your problem. I guess it is either an error in your PHP code which generates the links or an erroneous client (or a hacker) is accessing your site
Looking at the error-URLs, it seems like the paths to some images are generated dynamically by concatenating strings; but the quotes are note set correctly.
/my_directory/'%20+%20protocol_host%20+%20'/images/greenthumb.png
without URL encoding is
/my_directory/' + protocol_host + '/images/greenthumb.png
PHP uses . to concatenate strings, but here a + is used. So I would guess that some JavaScript code causes this error.
Check your JS resources!
I would guess, that you are linking some resources relatively without a leading slash.
example:
<img src="images/foo.png" />
usually this leads to urls like http://example.com/images/foo.png instead of http://example.com/my_project/images/foo.png but can have other conseques as well.
This is just a guess though.

AJAX / PHP not working on new WAMP server

We've moved a php page from one WAMP server to another and the chap who created it has left the business. I know nothing about AJAX, so am struggling!
I've scoured the code on both the old server and new, and it's exactly the same but for some reason the AJAX on the new server isn't working correctly, whereas on the old server it's fine.
What it's supposed to do is show a list of people from our database, allow users to update those records and then show the new, updated record without refreshing the page.
On the old server, it works a treat but on the new server it doesn't load the new data through. It's probably something ridiculously basic, but I'm scratching my head (mainly as I know nothing about the technology!)
Any help much appreciated.
Have you made sure the script that you are requesting with AJAX is actually there? You have said you've uploaded the script but is the path exactly the same? Different environments may have different paths to the same script.
Also how are you making the AJAX request? Are you using (for example) the jQuery library that might exist on one environment but not the other? Are they both using the same version of jQuery?
Use the Javascript console to see what errors you're getting and go from there. Chrome and Firefox have the best ones by default.
https://developer.mozilla.org/en/Error_Console
Before any of this though I would make sure the original script is working and returning the right results.
First check:
Look into the Javascript code and find where the actual URL is constructed.
It will look like:
xmlhttp.open("GET","yourAjaxPage.php",true);
but the xmlhttp can have a different name.
Now, simply alert this URL, or document.write(), or anything that gives you the url.
Put this URL into the browser-url and see the response.
In case you are using a session, make sure you use the same browser (TAB for example) where you expect the result.
Now you will see the response from the server to the request you just made. This should get you going finding the problem.
With the error console we were seeing an error 500 from the server (which seemed odd and rather unspecific...!)
Having had someone we know take a look at the code, it seems that on the old server, it seemed quite happy using mssql_close($con); but on the new server it didn't and so simply replacing it with sqlsrv_close($con) then meant the page the ajax was calling could complete and then returned the results as expected!
Always the little things...!

Weird query: "equal slash id" (=/id) gives weird error: 501

This is the weirdest problem of my life, and can't even Google it. It's happening on an Apache powered website written in PHP, which uses mod_rewrite (but that's not the issue, I tried removing the .htaccess file, problem still exists).
If I have a query string that looks exactly or similar to: =/id I get an 501 response:
Method Not Implemented
GET to / not supported.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
I never written such error page, never sent an 501 response, don't have the slightest clue where this thing is coming from. Originally I had a long URL giving me a similar error, but I stripped down to this little snippet above. If I remove or change any character, the error's gone.
If that helps: my website is commentards.net, and the original URL was an openid login request which looks like this:
http://commentards.net/q/user/auth?openid_identifier=https://www.google.com/accounts/o8/id
from which the query string is:
?openid_identifier=https://www.google.com/accounts/o8/Fid
I asked the support team, and they said it was mod_security, and disabled it for my website. And now it works fine. I should have started with that. Anyway, thanks for your help.
Urlencode your query string parameter(s).
https://www.google.com/accounts/o8/id
becomes
https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2FFid
http://commentards.net/q/user/auth?openid_identifier=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2FFid works fine, so HerrSerker already answered your question.

PHP Javascript page loads twice

I have written this small site, with registration and everything, and I got to a point I think I am not too sure what is happening.
It first started as the DB reporting to me that the user I am trying to write into the DB has a duplicate entry (where it should be unique), which really puzzled me, how can it be that I have duplicate ? Well. It took me three days to realize that the page is being somehow called twice !
I put a
$_SESSION['one']=0;
and a
$_SESSION['two']=0;
in the topmost and bottommost parts of the page accordingly.
then I changed them both to ++, so I can check how many times they have been passed through.
I used the verification link from the emaill the site has sent, and tested their values.
Strangely enough, 'one' would equal 2 and 'two' would equal 1...
This explains exactly why all worked registration-wise, but I got all those errors about those duplicates.
Though, I used firebug to trace any redirections, but couldn't see anything...
It shows the page has 12 GETs and a POST.
I was hoping to bump into a redirect and debug accordingly, but alas, or maybe I don't know how to use firebug to trace these redirects...
I would appreciate any suggestion
Thanks in advance!
Like I said in the comments, here is the answer that worked for me and Ted:
What I do to fix it is change my doctype to html 5 and then validate the page using w3c validator, this problem was only occurring for my in firefox using firebug.
Do you have some <img> or <script> with src=""? Or maybe some <link> stylesheet with empty href?
Is firebug showing you, in net tab, that your site is called twice?
This kind of issues usually happen when you have a fatal or otherwise unignorable error that forces PHP to terminate you script early, in the midst of processing a request.
Check you error log for details of happening.
It is Firebug that is causing the page to load twice. Apparently changing the doctype to html5
as:
instead of html4 has overridden that bug.
When you are going to deploy your site, go back to html 4, and of course, always keep the server safe from such bugs. Use DB constraints, validation and escaping when needed.
Hope this helps, and Big thanks to #jeffreydev!!

Categories