includes problem

They have: 461 posts

Joined: Jul 2003

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?

not: carriage returns added in code to minimize norizontal scroll (in the preview there is none left)

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

<?php
         
<!-- nav bar-->
      <
table frame=\"void\" bgcolor=\"#000000\" border=\"0\" cellpadding=\"0\"
cellspacing=\"0\" text=\"#c8c8c8\" width=\"750\">
      <tr>
        <td>
          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\">
          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)
<?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
}
?>

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

I'm not sure what the problemo here is, but you have an open <? tag at the top and then you open with a <?php tag
Is it not working as in it doesn't check if they're logged in or not?

Laughing out loud

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Just a quick glance... your heredoc syntax looks invalid. The string 'END' in your source should start at the begining of the line to end the echo statement.

I don't have time to examine the code right now. I need to be up in 6.5 hours, and I haven't slept yet. I'll look it over tomorrow if I remember.

Mark Hensler
If there is no answer on Google, then there is no question.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

One thing I noticed is that (for me) using:

echo<<http://ca3.php.net/echo for more detail.

In the first one, you need to lose the surrounding <? ?>, they will just cause errors as the php is all contained within the code with its own set of <? ?> where needed.

They have: 461 posts

Joined: Jul 2003

i think it's case sensitive that whatever you type after <<< must match the second occurance exactly

ok. it's got to be the calll 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.

<?php
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;
}
?>

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

You cannot have white space around the END; -- it has to be at the very beginning of the line and on a line all by itself.

ECHO should be echo <-- lowercase.

What is the error? Please post it. Smiling

They have: 461 posts

Joined: Jul 2003

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

which is the cookie... and it's not white space... it's the pretty printing that xemacs added... besides, when i took that out it still gave the error

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

<?php
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;
?>

You have the above now?

line 103 is the cookie itself? Can you show the code for it? (looks like whitespace to me, but if you are sure that END; is right at the beginning of the line, that E is the first character of the line, then it *should* work.)

They have: 461 posts

Joined: Jul 2003

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

this also happens to be the third function to get parsed....i would expect one of the earlier ends to give an error if the end was the issue

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I don't suppose you've copied this code from somewhere? Like from a browser window? If so, you might want to select one of the "spaces" and do a search and replace on it with a real space. PHP code in a browser uses &nbsp; for spaces, which will be unreadable to PHP if left in.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

From what I can see, line 103 looks fine. My initial thought is a missing single quote in the lines above.

Quote: Originally posted by m3rajk
i would expect one of the earlier ends to give an error if the end was the issue

Nope. Not always. In this case, I don't think the interpreter has checked the syntax of the file below line 103, where it has encountered an error.

Just to stress the situation of your heredoc syntax, let me echo a quote from the php manual:

Quote: It is very important to note that the line with the closing identifier contains no other characters, except possibly a semicolon (Wink. That means especially that the identifier may not be indented, and there may not be any spaces or tabs after or before the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by your operating system. This is \r on Macintosh for example.

If this rule is broken and the closing identifier is not "clean" then it's not considered to be a closing identifier and PHP will continue looking for one. If in this case a proper closing identifier is not found then a parse error will result with the line number being at the end of the script.

Also note that PHP is, for the most part, case-insensitive. Functions are not case-sensitive, variable names are not case-sensitive, *but* the heredoc delimiter *is* case-sensitive.

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 461 posts

Joined: Jul 2003

turns out mark was right. as soon as i manually took out the spaces xemacs kept putting in as i typed the function.....
http://24.91.157.113/findyourdesire/phpTest/faq.php

normally those things are rather helpful.

and that was actually form one of the two include files.. namely the one with all the functions used by more than one page.

POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.