Page 1 of 1

XXAMPP echos out too much?

PostPosted: 16. May 2016 14:24
by BenGeocth
Here is some code.
Code: Select all
<?
               function controlStringErrors($string){
                  $string = str_replace("'", " ", $string);
                  $string = str_replace('"', " ", $string);
                  return $string;
               }
               if (!isset($_POST['Continue']))
               {
                  echo '<div class="forminfo">Oops! You must have come here by accident. Click <a href="http://www.lowdownbids.com">here</a> to continue on.</div>';
                  exit();
               }
               else
               {
                  require_once("Database.php");
                  $name=controlStringErrors($_POST['name']);
                  $lname=strtolower($name);
                  $username=controlStringErrors($_POST['username']);
                  $password=controlStringErrors($_POST['password']);
                  $address=controlStringErrors($_POST['address']);
                  
                  for ($i=0; $i<strlen($zip); i++)
                  {
                     switch(substr($zip, $i, 1)){
                        case 9:
                           $goodstring=true;
                           continue;
                        case 8:
                           $goodstring=true;
                           continue;
                        case 7:
                           $goodstring=true;
                           continue;
                        case 6:
                           $goodstring=true;
                           continue;
                        case 5:
                           $goodstring=true;
                           continue;
                        case 4:
                           $goodstring=true;
                           continue;
                        case 3:
                           $goodstring=true;
                           continue;
                        case 2:
                           $goodstring=true;
                           continue;
                        case 1:
                           $goodstring=true;
                           continue;
                        case 0:
                           $goodstring=true;
                           continue;
                        default:
                           $goodstring=false;
                     }
                     if (!$goodstring)
                     {
                        break;
                     }
                  }
                  $zip=controlStringErrors($_POST['zip']);
                  
                  
                  //check if the username is taken
                     $username_taken=false;
                     if ($username_taken)
                     {
                        echo "The username '$name' is taken!";
                     }
                     
                  $email=controlStringErrors($_POST['email']);
                  echo "<div class=\"forminfo\">A confirmation email has been sent to '$email'</div>";
               }

            ?>


In the case where $_POST['submit'] isn't defined, here is what the user is shown.

Oops! You must have come here by accident. Click here to continue on.'; exit(); } else { require_once("Database.php"); $name=controlStringErrors($_POST['name']); $lname=strtolower($name); $username=controlStringErrors($_POST['username']); $password=controlStringErrors($_POST['passwrod']); $address=controlStringErrors($_POST['address']); for ($i=0; $iA confirmation email has been sent to '$email'"; } ?>

Why isn't it stopping at the single quote after the word on?

Re: XXAMPP echos out too much?

PostPosted: 16. May 2016 16:51
by JJ_Tagy
My guess is because you have an unescaped open quote in your replace function.

Re: XXAMPP echos out too much?

PostPosted: 16. May 2016 17:42
by BenGeocth
JJ_Tagy wrote:My guess is because you have an unescaped open quote in your replace function.

But it works just fine on my actual website. Cleary it's XXAMPP.

Re: XXAMPP echos out too much?

PostPosted: 16. May 2016 18:10
by Nobbie
BenGeocth wrote:Cleary it's XXAMPP.


Cleary it's you.

You are doing lots of errors, the three most important:

a) You do NOT evaluate $_POST['submit'] in your code, but $_POST['Continue'] instead.

b) You did not use <?php in your code, but short tag <? instead. This is not enabled per default in Xampp and leads to "surprising" behaviour, as your PHP code now is simply HTML comment and is not executed.

Alread these severe errors may lead to the effect you recognize

c) You blame Xampp to do it wrong. This is dumb and pretty wrong. That would be such a severe error, thousand of Users would complain against Xampp, as it would not run on any server. "Clearly" is nothing, besides the fact, that is clearly you and your faulty code. You should be more humble.

Re: XXAMPP echos out too much?

PostPosted: 16. May 2016 18:26
by BenGeocth
Nobbie wrote:
BenGeocth wrote:Cleary it's XXAMPP.


Cleary it's you.

You are doing lots of errors, the three most important:

a) You do NOT evaluate $_POST['submit'] in your code, but $_POST['Continue'] instead.

b) You did not use <?php in your code, but short tag <? instead. This is not enabled per default in Xampp and leads to "surprising" behaviour, as your PHP code now is simply HTML comment and is not executed.

Alread these severe errors may lead to the effect you recognize

c) You blame Xampp to do it wrong. This is dumb and pretty wrong. That would be such a severe error, thousand of Users would complain against Xampp, as it would not run on any server. "Clearly" is nothing, besides the fact, that is clearly you and your faulty code. You should be more humble.

I've already said it works on my actual website. Perfectly. I need a secure testing environment. The only real problem is that I used <? instead of <?php which I didn't realize was a problem with XXAMPP- I was trying to just save keystrokes. And I appreciate your concern, but it does no one any good to tell me to be humble. I do thank you for the assistance with the php tag issue, though. I'll have a look and see if it fixes the problem.

EDIT: Thank you, that was it. Despite running fine on my website without the php part, xxampp doesn't recognize.

So, yes, in essence it was XXAMPP. Please relax before you burst a blood vessel. Again, thank you.

Re: XXAMPP echos out too much?

PostPosted: 16. May 2016 18:45
by metro82
Nobbie wrote:
BenGeocth wrote:Cleary it's XXAMPP.


Cleary it's you.

c) You blame Xampp to do it wrong. This is dumb and pretty wrong. That would be such a severe error, thousand of Users would complain against Xampp, as it would not run on any server. "Clearly" is nothing, besides the fact, that is clearly you and your faulty code. You should be more humble.


Bravo Nobbie! Well said! :wink: I can't believe anyone would actually have the audacity to blame XAMPP for anything. Seriously? No doubt this thread has to rank up there IMO as one of the more ridiculous posts I think I have come across over the few months I have been reading this forum. Wow.

Just when you think you've seen it all, you get a post like this guy's... Amazing. :|

I hate to sound so rude on here (although I'm honestly not trying to ... it is only when I see posts like these) ... but seriously -- complaining/blaming anything on XAMPP is about the most absurd thing I think I have read on this forum IMO. :roll:

Re: XXAMPP echos out too much?

PostPosted: 16. May 2016 19:00
by BenGeocth
You still haven't addressed why it would work perfectly in an actual server but not in XXAMPP. Obviously, my code is solid, so I think there's plenty of room for criticism. Especially when there's an obscure user feature that's never mentioned or referenced in the control panel that states "you MUST use <?php, NOT <?"

So, yes, when I see perfect code working in different sources, then not in this one, I will have the "unbelievable audacity" to question that there was an issue with the program. I never even insulted XXAMPP. I civilly asked a question, and when the conclusion arose that the issue is not my code, the only other factor left was the program.

Sure, the program works fine now, but you guys are really banding hard against me for a cause that it's completely justified on both sides. Bit of an ego thing, really.

Re: XXAMPP echos out too much?

PostPosted: 16. May 2016 19:21
by Altrea
Hi,

BenGeocth wrote:You still haven't addressed why it would work perfectly in an actual server but not in XXAMPP.

Quite easy, it is a question of configuration. There is a setting to enable short open tags even in XAMPP.
But PHP recommends to disable short open tags for compatibility reasons (they have some issues if you want to use xml open tags <?xml).

php.ini wrote:; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It is
; generally recommended that <?php and ?> should be used and that this feature
; should be disabled, as enabling it may result in issues when generating XML
; documents, however this remains supported for backward compatibility reasons.
; Note that this directive does not control the <?= shorthand tag, which can be
; used regardless of this directive.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag


So using short open tags is generally speaking sloppy programming. Your hoster enables short tags to minimize support questions because of sloppy programming.
I hope you can see now that blaming XAMPP for this is not the right way.
Blame the internet that teaches you to use short open tags but hiding the fact that this is bad practise and can cause other issues.

best wishes,
Altrea

Re: XXAMPP echos out too much?

PostPosted: 16. May 2016 19:36
by Nobbie
BenGeocth wrote:Sure, the program works fine now, but you guys are really banding hard against me for a cause that it's completely justified on both sides. Bit of an ego thing, really.


No, you are simply still wrong. Its NOT both sides. Its on your side ONLY. Xampp comes with a different configuration than your hoster. This is quite normal in some cases. Its the goal of configurations to configure the software to your needs. Otherwise you would not need any php.ini.

Its you and only you who lacks the skill about PHP and php.ini, at least the skill about short tags and the cons and pros. You simply dont know anything about that and that (and only that) is the reason for the failure of your code. Your code does not fit to the configuration. Who is to blame for that? You. Nothing else, nobody else.

Re: XXAMPP echos out too much?

PostPosted: 18. May 2016 17:03
by gsmith
How can this exact code work on another server?
line 21 of that snipit
Code: Select all
for ($i=0; $i<strlen($zip); i++)

Notice anything about the i++? Like it's missing the $, $i++.

Of course you have already figured this out using php's syntax check right?
Code: Select all
S:\Xampp\apache\htdocs\hackit>php -l snipit.php
PHP Parse error:  syntax error, unexpected '++' (T_INC), expecting ')' in snipit.php on line 21

Parse error: syntax error, unexpected '++' (T_INC), expecting ')' in snipit.php on line 21
Errors parsing snipit.php