Topic: $cur_user['username']

hello, i have this script:

<?php 
if($cookie['is_guest'])
{
print("Welcome to our forums! You have to register first, or please login.");
}
else
{
print("hello, $cur_user['username'], welcome to our forums!");
}
?>

I placed this code in index.php. But it doesn't work. It gives this parse error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/basalph/public_html/forum/index.php on line 49

Why is this?

Re: $cur_user['username']

Try this:

print("hello, ".$cur_user['username'].", welcome to our forums!");

"Programming is like sex: one mistake and you have to support it for the rest of your life."

3 (edited by Paul 2004-03-01 15:16)

Re: $cur_user['username']

Don't you have to join strings to variables i.e. you can't just dump a variable in the middle of a string.

("hello, ".$cur_user['username'].", welcome to our fourms!");

My code is probably wrong but I think that is the problem and somebody will no doubt correct my coding efforts.

[EDIT]

Rickard must have replied while I was composing this. At least it's nice to know I got the code right.

4 (edited by basalphenaar 2004-03-01 16:40)

Re: $cur_user['username']

ok, tnx for help wink

edit:
it works smile

Re: $cur_user['username']

i just soooooooo don't get it, that code won't work for me. even if i logged in to the forum
http://www.dutcholsentwins.com/uhm.php always sees me as a guest (so nothing appears on the sccreen). I have that problem on my own computer, on someone elses computer and on the computers of school...

Re: $cur_user['username']

And you have included common.php before running that code I hope?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: $cur_user['username']

yes i have :s

Re: $cur_user['username']

Could you show me the whole piece of code that isn't working?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: $cur_user['username']

sure thing smile

<?
$pun_root = './forum/nl/';  // Path to the forum root directory (must be defined)
require $pun_root.'include/common.php';

if ($cookie['is_guest'])
{
    // The visitor is a guest. Do whatever.
}
else
{
    // The visitor is logged in.

    echo 'Hello '.pun_htmlspecialchars($cur_user['username']);
}
?>

Re: $cur_user['username']

And what settings do you have for cookie_domain and cookie_path in your config.php?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

11

Re: $cur_user['username']

this is what i have in config.php

$cookie_domain = '';
$cookie_path = '/';

might it have something to do with the fact cookie_domain is empty?

12

Re: $cur_user['username']

Could this have anything to do with there being two forums installed for different languages sharing a common membership and presumably a common cookie?

I have just checked my cookie_domain on my own PC and on a remote server. In both cases my settings are the same as yours.

Re: $cur_user['username']

I honestly have no idea what's wrong. My guess is that it is related to cookies somehow, but I'm not sure how.

Try just running dump($cookie); after including common.php. What does it output?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

14

Re: $cur_user['username']

this is the output, whether i'm logged in or logged out..in both cases i get this as the output:

Array
(
    [username] => Guest
    [is_guest] => 1
)

Re: $cur_user['username']

Ok, try this. Replace all the code above with this:

dump($_COOKIE);

"Programming is like sex: one mistake and you have to support it for the rest of your life."

16

Re: $cur_user['username']

this is the output when i do that:

Array
(
)

Re: $cur_user['username']

That means that, for some reason, there is no valid cookie set at all. Well, not one that the script has access to anyway.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

18

Re: $cur_user['username']

but why? sad
anything that could fix it?

Re: $cur_user['username']

You aren't visiting the page by going to a different URL than you normally do?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

20

Re: $cur_user['username']

uhm, well.. i visit the forums by going to http://forum.dutcholsentwins.com
and i visit the site by going to http://www.dutcholsentwins.com
so they are both the same domain... dutcholsentwins.com

21

Re: $cur_user['username']

One thing I noticed, and I don't know if it means anything. DOT produces a cookie which is @forum.dutcholsentwins.com. Is this treated as the same domain as @dutcholsentwins.com. The reason I ask is that PunBB's cookie is @punbb.org even though the url is forums.punbb.org.

Re: $cur_user['username']

Try this:

$cookie_domain = '.dutcholsentwins.com';

You will probably have to log in again.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

23 (edited by jochem 2004-03-07 15:41)

Re: $cur_user['username']

yes, thank you, it worked.

24 (edited by jochem 2004-03-07 15:41)

Re: $cur_user['username']

never mind, solved it