Your Turn, Part Two

MrTerry
Posts: 34
Joined: Tue Jan 26, 2010 11:44 am

Post by MrTerry »

hi everybody

i m new to php so it is quite a challenge for me ... all i get is "error" XD
i made a site which creates a text file whenever my url is opened with a set parameter

if get parameter is used my code searchs for a file with this name in my webspace

but it seems this challenge doesnt even tries to set or get ..... firebug doesnt seem to give me a clue
is there a tool which can show me which actions were tried?

thx
Terry
michuber
Posts: 57
Joined: Sun Oct 26, 2008 3:30 pm

Post by michuber »

MrTerry wrote:is there a tool which can show me which actions were tried?
You should take a look at your server's access and error log.
markobr
Posts: 17
Joined: Thu May 20, 2010 4:09 pm
Location: Tübingen
Contact:

Post by markobr »

Yep, to me it sends 8 requests and accepts answers in text/plain.

And just a remark from the nitpicker in me: What I write to solve this is technically not a "server" (which would listen on a port) but a CGI script (which is called by the webserver already in place).
skooli
Posts: 2
Joined: Sat Oct 16, 2010 12:18 pm

Post by skooli »

For clarification: you have to remember ALL set values, not just the last one.
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

I too get the 'error' answer when submitting my solution. Here is what I get when I access my freely-hosted website manually. The real server name has been replaced by "redacted.xyz", and the displayed answer is the string within the quotation marks:

http://redacted.xyz/index.php?get=test1
answer: "no"

http://redacted.xyz/index.php?set=test1
answer: "" (empty page)

http://redacted.xyz/index.php?get=test1
answer: "yes"

http://redacted.xyz/index.php?set=test2
answer: "" (empty page)

http://redacted.xyz/index.php?get=sometext
answer: "no"

http://redacted.xyz/index.php?get=test2
answer: "yes"

Actually, what do we have to send as a reply when setting a variable? It seems to me that the challenge does not really specify that. For the 'get' this is clear, yes or no depending on whether the referenced variable has been set previously or not.

I also tried a "yes" reply instead of an empty string when setting a variable, but to no avail.
User avatar
bsguedes
Posts: 103
Joined: Tue Feb 24, 2009 12:39 am
Location: Porto Alegre

Post by bsguedes »

I'm still stuck in this challenge, even having a script working correctly with manual testing.

I know almost nothing of PHP, does a simple " echo 'yes'; " or " echo 'no' " work to return the answer asked by the challenge ?

Would someone who solved the challenge be kind enough to test my URL if I send it via PM?

Thanks.
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

Do you have your page hosted by a provider who allows access to the server logs? Because mine does not, at least not for free accounts. I think that this could help in finding out where things are going wrong.
rmplpmpl
Posts: 113
Joined: Sun Oct 26, 2008 10:38 am
Location: Germany

Post by rmplpmpl »

bsguedes wrote:I'm still stuck in this challenge, even having a script working correctly with manual testing.

I know almost nothing of PHP, does a simple " echo 'yes'; " or " echo 'no' " work to return the answer asked by the challenge ?

Would someone who solved the challenge be kind enough to test my URL if I send it via PM?

Thanks.
this should to the trick. you can PM me your URL (going to bed now, though)
megabreit
Posts: 141
Joined: Sat Jan 03, 2009 3:33 pm

Post by megabreit »

In many challenges a source of pain: Did you check your output for "hidden" characters like "carriage return" or "line feed"?
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

megabreit wrote:In many challenges a source of pain: Did you check your output for "hidden" characters like "carriage return" or "line feed"?
Hm, while you are in general right about this being a thing to consider, I don't see how something like:

Code: Select all

<?php

$answer = "megabreit";
print $answer;

?>
could generate unwanted characters at the end of the output, that is after the "t" in this example?
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

if you look at your page through something like CURL you will be able to see every byte of output, you will probably see an newline thanks to Apache/Zend being kind enough to throw in a newline at the end, I think there is a way around this that doesn't involve modifying settings
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

Does that mean that the webserver could deliver a newline, but the browser would not display it? Fantastic. :(
rmplpmpl
Posts: 113
Joined: Sun Oct 26, 2008 10:38 am
Location: Germany

Post by rmplpmpl »

megabreit wrote:In many challenges a source of pain: Did you check your output for "hidden" characters like "carriage return" or "line feed"?
Exactly this seems to be the problem of bsguedes. It was "visible" in the browser as well.

edit: i just remembered that this seems to be another difference when using echo instead of print, which is pretty odd
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

rmplpmpl wrote: Exactly this seems to be the problem of bsguedes. It was "visible" in the browser as well.

edit: i just remembered that this seems to be another difference when using echo instead of print, which is pretty odd
On my machine, I see no difference between:

Code: Select all

<?php
echo "yes";
?>
and

Code: Select all

<?php
print "yes";
?>
when saving the pages to hard disk and comparing them. Also "View Page Source" within the browser does not show any Carriage Return/Line Feed or other superfluous characters. This is on Windows XP SP3, Apache 2.2.19, PHP 5.2.17, Mozilla Firefox 3.6.18.

Now if this were platform dependent or version dependent, that would make it even worse.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

If I recall you can avoid the additional newline by leaving off the closing PHP tag, I think that was the reason why the Expression Engine extensions rules state you must leave off the closing tag for extensions as the newline can cause problems when it is imported. I would still suggest you check out your pages output using something like CURL to show the response quite literally byte for byte as I remember Firefox doing stuff where newlines and maybe tabs/white space were concerned. I don't know about it's normal operation with newlines but I read on php.net that print has/does return(ed/s) a newline character if it is given a null string so may be appending a newline onto text anyway.

All that aside you should be able to manage it in the end as I did it with PHP some time ago although I appreciate config may be different but it shouldn't be too much of a problem if you a thorough.
Post Reply