Page 1 of 1

issue in code after moving to includes

Posted: Fri Aug 01, 2003 11:39 pm
by m3rajk
i'm having a problem with the includes file. i did a slight change with adding a cookie to track if you're logged (specifically, but i'm thinking of checking username and pw and then if they match something have you noted as logged in)

i tried changng the cookie back to no avail. can anyone tell me why the previous one worked and the one from the function doesn't?

previous one (part of the begining of most pages, was near the top once the html started)

Code: Select all

<?
          <!-- nav bar-->
      <table frame="void" bgcolor="#000000" border="0" cellpadding="0" cellspacing="0" text="#c8c8c8" width="750">
	  <tr>
	    <td><?php
	      if(isset($_COOKIE['un'])){ echo '<a href="logout.php">Log Out!</a>'; } # you're logged in
	      else{ echo '<a href="login.php">Log In!</a>'; } # you're not logged in
	      ?></td>
	    <td><a href="faq.php?seek=all">F.A.Q. & T.O.S.</a></td>
	    <td><a href="new.php?gen=all">New Users</a></td>
	    <td><a href="top.php?gen=all">Top Users</a></td>
	  </tr>
	  <tr>
	    <td valign="top"><?php
	      if(isset($_COOKIE['un'])){ echo '<a href="control.php">Control Panel</a>'; } # you're logged in
	      else{ echo '<a href="signup.php">Sign Up!</a>'; } # you're not logged in
	      ?></td>
	    <td valign="top"><a href="forums.php">Forums</a></td>
	    <td valign="top"><form name="qsearch" action="profile.php"><input type="text" maxlength="15" size="15" name="un"></td>
	    <td valign="top"><input type="submit" value="Find User!"></form></td>
	  </tr>
      </table>
      <!-- /nav bar -->
?>
the one from the includes (it's own function)

Code: Select all

<?php
function nav(){ # inserts navigation bar
  ECHO <<<END
      <!-- nav bar-->
      <table frame="void" bgcolor="#000000" border="0" cellpadding="0" cellspacing="0" text="#c8c8c8" width="750">
	  <tr>
	    <td>
    END
  if($_COOKIE['login']){ echo '<a href="logout.php" target="_top">Log Out!</a>'; } # you're logged in
  else{ echo '<a href="login.php" target="_top">Log In!</a>'; } # you're not logged in
  ECHO <<<END
	      </td>
	    <td><a href="faq.php?seek=all" target="_top">F.A.Q. & T.O.S.</a></td>
	    <td><a href="new.php?gen=all" target="_top">New Users</a></td>
	    <td><a href="top.php?gen=all" target="_top">Top Users</a></td>
	  </tr>
	  <tr>
	    <td valign="top">
    END
  if($_COOKIE['login']){ echo '<a href="control.php" target="_top">Control Panel</a>'; } # you're logged in
  else{ echo '<a href="signup.php" target="_top">Sign Up!</a>'; } # you're not logged in
  ECHO <<<END
	      </td>
	    <td valign="top"><a href="forums.php" target="_top">Forums</a></td>
	    <td valign="top"><form name="qsearch" action="profile.php" target="_top"><input type="text" maxlength="15" size="15" name="un"></td>
	    <td valign="top"><input type="submit" value="Find User!"></form></td>
	  </tr>
      </table>
      <!-- /nav bar -->
    END
}
?>

Posted: Sat Aug 02, 2003 9:26 am
by nielsene
You are never ending your HEREDOC. The END must be on a line by itself, with no whitespate before it. Plus I would move the if/elses
to before the HEREDOC and combine it just to one HEREDOC.

Code: Select all

if (isset($_COOKIE["un"]))
{
    $link1 = // logout
    $link2 = // control panel
}
else
   $link1 = //log in
   $link 2 = //sign up
}
$navbar =<<<END_BAR
      <!-- nav bar-->
      <table frame="void" bgcolor="#000000" border="0" cellpadding="0" cellspacing="0" text="#c8c8c8" width="750">
     <tr>
       <td>$link1</td>
       <td><a href="faq.php?seek=all" target="_top">F.A.Q. & T.O.S.</a></td>
       <td><a href="new.php?gen=all" target="_top">New Users</a></td>
       <td><a href="top.php?gen=all" target="_top">Top Users</a></td>
     </tr>
     <tr>
       <td valign="top">$link2</td>
       <td valign="top"><a href="forums.php" target="_top">Forums</a></td>
       <td valign="top"><form name="qsearch" action="profile.php" target="_top"><input type="text" maxlength="15" size="15" name="un"></td>
       <td valign="top"><input type="submit" value="Find User!"></form></td>
     </tr>
      </table>
      <!-- /nav bar -->
END_NAV;
   echo $navbar;  // I would rather do return $navbar;  functions shouldn't generate output directly....

Posted: Sat Aug 02, 2003 12:37 pm
by m3rajk
thank you

althougth there's a few before that and i think there's a space before the END call. i should probalby fix them as well. i decided to use them in the includes because for future editing it's easier to go $variable than <?php echo $variable; ?> and someone posted that it's actually faster than popping in and out of php.

since i've noticed you've actually corrected some of them on other things, do you know if there's any truth to that?

Posted: Sat Aug 02, 2003 12:45 pm
by nielsene
I actually don't know. I've never benchmarked it.

For what its worth I never leave PHP mode. All my display is done via echo of
variables, typically built up using heredocs.

Posted: Sat Aug 02, 2003 1:38 pm
by m3rajk
as you can tell i'm moving to that. it displays rapidly enough on the p1 pre mmx / 166 mhz that once the db is added the slow will be the db, so i'm not concerned.

what does concern me is that this problem merely changed here it is...

it's got to be the call to the cookie, because i changed it to this and it's still giving me the same error and the line changed to where the call to the cookie ie. i don't understand why though.

Code: Select all

<?
function nav(){ # inserts navigation bar
  if(isset($_COOKIE['login'])){ $login=$_COOKIE['login']; } # you've got a cookie
  else{ $login=FALSE;} # you haven't been here
  if($login){ # you're logged in
    $link1='<a href="logout.php" target="_top">Log Out!</a>';
    $link2='<a href="control.php" target="_top">Control Panel</a>';
  }else{ # you're not logged in
    $link1='<a href="login.php" target="_top">Log In!</a>';
    $link2='<a href="signup.php" target="_top">Sign Up!</a>';
  }

  ECHO <<<END
      <!-- nav bar-->
      <table frame="void" bgcolor="#000000" border="0" cellpadding="0" cellspacing="0" text="#c8c8c8" width="750">
          <tr>
            <td>$link1</td>
            <td><a href="faq.php?seek=all" target="_top">F.A.Q. & T.O.S.</a></td>
            <td><a href="new.php?gen=all" target="_top">New Users</a></td>
            <td><a href="top.php?gen=all" target="_top">Top Users</a></td>
          </tr>
          <tr>
            <td valign="top">$link2</td>
            <td valign="top"><a href="forums.php" target="_top">Forums</a></td>
            <td valign="top"><form name="qsearch" action="profile.php" target="_top"><input type="text" maxlength="15" size=
"15" name="un"></td>
            <td valign="top"><input type="submit" value="Find User!"></form></td>
          </tr>
      </table>
      <!-- /nav bar -->
    END;
}
?>

Posted: Sat Aug 02, 2003 2:03 pm
by nielsene
Well you're END marker is still after some whitespace os your heredoc isn't ending....

What error is it giving you?

Posted: Sat Aug 02, 2003 3:05 pm
by m3rajk
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/joshua/includes/fyd.unifunc.php on line 103

this happens to be the 4th function done with that type of echo (and there's no other issue in that file. the issue for the other file is that it's calling a function from that one)

line 103: if(isset($_COOKIE['login'])){ $login=$_COOKIE['login']; } # you've got a cookie

Posted: Sun Aug 03, 2003 7:32 am
by twigletmac
This:

Code: Select all

END;
has to be

Code: Select all

END;
as nielsene said. As for the error - what's happening on the lines above the error line? It's probably an issue with a function before it that's causing the issue for nav().

Mac

Posted: Sun Aug 03, 2003 12:51 pm
by m3rajk
i din't get a chance to come back last night. that was the 4th and final function and second one called.

i figured since xemacs kept sticking it in that it's still the first thing, but tried moving them after i made that post. putting them on the next line in that file worked fine, so i'm guessing it's a combo between the fact xemacs insisted on indenting it (first time the indenting has ever worked against me) and the fact there were three previous functions that were incorrect as a result

Posted: Sun Aug 03, 2003 3:02 pm
by nielsene
YES! all the PHP-mode syntax highlighters act very funny with heredocs... I've submitted bug reports to about four different sets of maintainers, but none seem to think its a big deal... I guess they don't use heredocs.....

Posted: Sun Aug 03, 2003 3:05 pm
by m3rajk
it's literally the only proble i've had with xemacs. my guess is that if i were to try in emacs it'd also have the issue...because they're both opensourrce and come from the same initial source.. diff is the two that started emacs wanted to take diff paths at some point, so they each took a copy and set up a healthy competition between the two. i prefer the x interface better.

if you wanted you could always make a patch and send it to them.i'd think about it but i want a job more. so it'd be something to do AFTER i get a job

Posted: Sun Aug 03, 2003 3:16 pm
by nielsene
Yeah, I normally use "regular" emacs, so yes it has the same problem.

Yes I could write a patch, or I could just decide to move all my heredocs to a phrasebook pattern as I've been chatting about in the Adv forum and leave them in either raw html/sql format and not worry about the funny indenting.... The latter sounds like a better s/w design anways....

Posted: Mon Aug 04, 2003 3:21 am
by twigletmac
nielsene wrote:YES! all the PHP-mode syntax highlighters act very funny with heredocs... I've submitted bug reports to about four different sets of maintainers, but none seem to think its a big deal... I guess they don't use heredocs.....
I sent an e-mail to the author of EditPlus about this since it's the one thing that irritates me about the program - I asked if it would be possible to set up another PHP delimeter (<<<END and END; alongside <? and ?>) to allow Edit+ to treat stuff in heredocs as simple HTML (and give me syntax highlighting). The answer I got back was:
EditPlus does not support the feature.
And that's it.

Oh, well.

Mac

Posted: Mon Aug 04, 2003 1:47 pm
by m3rajk
twig: have you ever tried xemacs or emacs? i know those would respond back "would you please create the plug it? then we'll incorporate it in the future"

personally i'm not sure where to begin...