Page 1 of 1

new to php. My echoed url is appending itself to the current

Posted: Sun Oct 02, 2011 7:02 pm
by paperfiction
I am a php beginner, hence my first post here. So hello people.
I have written the following code (for a wordpress page)

The idea is it adds a link to a page which takes me to another page

The code works fine when I am on my main page logged in as a user. ie http://www.mywebsite/
and when I click the link I get http://www.mywebsite/user1/anotherdirectory
When I move to another page like http://www.mywebsite/anotherpage.html - the echoed url from my link appends itself to the current url in the browser so I get
http://www.mywebsite/anotheruserspage.h ... directory/

My question is how do I stop it appending the url?

Code: Select all

<?php global $user_login;
get_currentuserinfo();
echo"<a href=\"$BASE_URL$user_login/anotherdirectory/\">dash</a>";
?>

Re: new to php. My echoed url is appending itself to the cur

Posted: Sun Oct 02, 2011 7:20 pm
by egg82
echo"<a href=\"http://$BASE_URL$user_login/anotherdirectory/\">dash</a>";

I had the same issue. Figured out that without http:// in front of it, it thinks of it as a directory or file within the current website

edit:
Sorry, didn't seem to quite get what you said. Looks like all you have to do it use $_SERVER['SERVER_NAME'] and $_SERVER['REQUEST_URI']
echo('<a href="http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].$user_login/anotherdirectory/.'">dash</a>";

Re: new to php. My echoed url is appending itself to the cur

Posted: Mon Oct 03, 2011 4:35 am
by paperfiction
Oh ok thanks, I will try that later when I get in.

Thanks for the quick reply