By lemonidas on
I have the following code in a drupal node (page)
<php?
echo '<h3>Welcome , '.$user->name.'!</h3>';
echo '<a href="'.$base_url.'/user/'.$user->uid.'">'.$user->uid.' profile</a> |';
echo '<a href="'.$base_url.'/user/'.$user->uid.'/edit/Personal+Info"><font size="1">edit</font></a><hr />';
?>
The page has more code after this, but i realized that whenever I request the $user->uid or the $user->name variable, the node doesn't even load if the user is anyone but the administrator.
I thought it might be the $user->name bit, but even the $user->uid doesn't work. Only the title shows and no other node element is rendered, and no error or warning is shown (i have error display ON in the settings).
Any ideas? Or maybe I'm missing something I should know.
Comments
i forgot
I forgot to mention, that i have
global $base_url;
global $user;
above this code snippet
and that this happens if I try to echo the $user->uid or name, (because when I use $user->uid in queries they work no matter who the user is)
Do you really have <php? ?
Do you really have
<php??It should be
<?php.HTH
Terry
Recent Drupal sites:-
www.allegiantair.com www.defaqto.com www.quarkexpeditions.com www.sportrelief.com www.chevronhackles.com
www.philipturnercrafts.co.uk www.intelflexplus.com www.aprilroseturner.com www.businessclubagent.ihg.com www.businessclub.ihg
lol No I have '<?php' (but
lol
No I have '<?php' (but maybe that's why the code highlighting didn't work and i used the < code > tags :)
Well I can tell you now that
Well I can tell you now that it doesn't break anything as I use it myself.
It would have been more helpful if you'd posted the actual code, but meh anyways - here's what I noticed from what you wrote;
You wrote
<php?rather than<?php, alsoechodoesn't tend to work very well (don't know why) I'd stick withprint- plus, I can't remember if the rest of $user is null, but certainly $user->uid is when the user is anonymous, why not try something more like this;Pobster
--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------
Thanks for your reply
Thanks for your reply.
I check for $user->uid before this code block (the page is a members only page).
I think that this block causes the thing to break, because when I comment it out, the rest of the page works for all users.
I'll try with print (but it's strange since I always use echo and the only page to cause problems is this one..)
Leonidas
Yeah I've noticed it caused
Yeah I've noticed it caused me a problem before, yet I've no idea why? Anyways, I thought I'd post my own snippet to show how I do it;
Pobster
--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------
ok freaked out by now
Multiple strange things happen.
I tried 'print' instead of echo and nothing happened.
I tried to place the block in an
if ($user->uid)block and nothing showed up.Then I placed only this line
print '<a href="'.$base_url.'/user/'.$user->uid.'/edit/Personal+Info"><font size="1">edit</font></a><hr />';in the if block (and all other commented out)) and strangely it worked!I tried the profile_load_profile($user); to print some user info and it worked (outside the if block).
I don't know where the problem might be. (and it's also strange that this happens to everyone but the administrator!)
PS: Thanks for your code and answers :)
UPDATE:
This works
This doesn't (and nothing is shown)
No new variables are used. I don't know wth is wrong with this.
why is your global $user; on
why is your global $user; on the inside of you if ($user->uid) { } ?
yes, sorry about that. it is
yes, sorry about that.
it is also outside of the if block.
Do you mean that you've got
Do you mean that you've got two separate php sections in your block? I don't think they 'carry over'? I think you'll have to redeclare global $user at the start of that section.
...As I said before, if you'd actually posted the complete code you're trying to use - most of this thread wouldn't exist as your problem would be solved by now...
Pobster
--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------
It works now (as shown
It works now (as shown above).
Thanks for your patience, i didn't want to post the code, since i think it is very poorly written (bad programming practices) and i would be ashamed to show it :/
Heh heh! ;o)
Heh heh! ;o) All the more reason to post it to make sure it doesn't contain some gaping security hole!!!
Glad you got it working,
Pobster
--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------
Where is the
Where is the profile_load_profile() function located? I searched every file in drupal and no method was found. I'm using 5.3 if that matters. Thanks.
---------------------------------------------------------------
My drupal site: Vacation-Places
Profile module
It is in the profile module
HTH
Terry
Recent Drupal sites:-
http://www.route324.com, http://www.univarpcp.co.uk, http://www.imagineanimation.net, http://62.73.185.61, http://www.shamusntash.com
Recent Drupal sites:-
www.allegiantair.com www.defaqto.com www.quarkexpeditions.com www.sportrelief.com www.chevronhackles.com
www.philipturnercrafts.co.uk www.intelflexplus.com www.aprilroseturner.com www.businessclubagent.ihg.com www.businessclub.ihg
Of course
Thanks fidot. I didn't setup my search to include .module's in Dreamweaver.
---------------------------------------------------------------
My drupal site: Vacation-Places