I have the below code in a php file on my webserver. It asks for a project ID, and then logs into an ftp site using that ID as part of the link (I am using the browser ftp functionality with login credentials like ftp://name:email@example.com). It works fine in FF and chrome, but when you open it in IE, enter the project ID and click on Go, it opens a Page Cannot Be Displayed. Any ideas would be greatly appreciated.
If the Show friendly HTTP error messages option on the Advanced tab of Internet Options is turned on, Internet Explorer does not generate an Authentication dialog box for you to enter the correct user name and password.
I unchecked this setting in IE options, advanced and the site now works. My problem now is to figure out how to have this setting changed from the server side somehow. My client won’t want to tell his users to go into IE to change that. He will want it to work without any effort on their part.
But that only works if I hard code the password into that line. I want to put a variable $pass there, but the way this line reads needs a colon between the username and password. So I have tried getting the $pass in my form action and then passing it to the location like this:
Beware though that sending the password plain-text over the internet is really prone to man in the middle attacks! And especially since this password would give them access to an ftp server this is a risk worth considering.
BTW. Why don’t you just let the users surf to ftp://ftp.example.com/ by themselves and let let them type in the projectid / password? What is the advantage of your PHP script doing it for them?
This is another reason why I recommend bumping those commands out to individual lines of code. Each line should do one thing (give or take, I don’t count things like concatenation). Assigning multiple variables on the same line just leads to a situation where bugs are more difficult to hunt down.
I realize that you probably think I’m harping on a small detail, but the second someone else tries to read your code, you immediately reduce the likelihood of getting a decent answer by clumping everything together on one line.
That doesn’t only apply to someone else reading your code.
Every once in a while I come by some code I wrote some years ago that needs changing, and I have to think really hard what’s going on in the code and what I should do to change it, and I feel like somebody else wrote it (although I’m sure I wrote it myself).
Because of this if changed my programming style about a year ago:
Use variable names that makes sense. Sure $nrpst for “Number of posts” makes sense while working on a project, but try reading the code a year later and you’ll be lost, just use $nrOfPosts and get an IDE with code completion
Don’t cram everything on one line, sure it looks cool and makes your code compact, but spaced out code is much easier to read and debug (as SituationSoap already said)
Use comments when you can see from a piece of code that its quite hard, or if you have a long piece of code to something complicated, put a comment here and there like “Now we will do this”, “Well, that seems to have gone wrong, let’s solve it by doing that and that”. We all know that writing comments can be tedious, but when you do it to outline a piece of complicated code, you’ll thank yourself later.