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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paperfiction
Forum Newbie
Posts: 2
Joined: Sun Oct 02, 2011 6:46 pm

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

Post 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>";
?>
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

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

Post 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>";
paperfiction
Forum Newbie
Posts: 2
Joined: Sun Oct 02, 2011 6:46 pm

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

Post by paperfiction »

Oh ok thanks, I will try that later when I get in.

Thanks for the quick reply
Post Reply