sinista Posted March 31, 2008 Share Posted March 31, 2008 hey people can some one help me write this propperly pls, here what i got <?php $url=$_COOKIE["username"]; echo ('<a href="http://localhost/members/$url/$url.php">My profile</a>'); ?> the above code gives me a link to http://localhost/members/$url/$url.php if the cookie value was set at 'sinista' i would like the link to direct me to http://localhost/members/sinista/sinista.php . so can someone help me write the link propperly pls thanks Link to comment https://forums.phpfreaks.com/topic/98883-hyperlink-help/ Share on other sites More sharing options...
metrostars Posted March 31, 2008 Share Posted March 31, 2008 Any variables contained inside single quotes won't be parsed, so... <?php $url=$_COOKIE["username"]; echo ("<a href=\"http://localhost/members/$url/$url.php\">My profile</a>"); ?> Link to comment https://forums.phpfreaks.com/topic/98883-hyperlink-help/#findComment-505970 Share on other sites More sharing options...
sinista Posted March 31, 2008 Author Share Posted March 31, 2008 ok so i kinda get what you just said variables in single quotes wont get passed but why did you add a slash after href? my code echo ('<a href="http://localhost/members/$url/$url.php">My profile</a>'); your code echo ("<a href=\"http://localhost/members/$url/$url.php\">My profile</a>"); ? Link to comment https://forums.phpfreaks.com/topic/98883-hyperlink-help/#findComment-505978 Share on other sites More sharing options...
metrostars Posted March 31, 2008 Share Posted March 31, 2008 Because you have to escape the " as PHP will think that the end of the echo is at the 2nd " , but it's not it's the fourth one, look at the change in colours below to understand... Correct: <?php $url=$_COOKIE["username"]; echo ("<a href=\"http://localhost/members/$url/$url.php\">My profile</a>"); ?> Incorrect: <?php $url=$_COOKIE["username"]; echo ("<a href="http://localhost/members/$url/$url.php">My profile</a>"); ?> so in the incorrect version, only <a href= will be echoed. Link to comment https://forums.phpfreaks.com/topic/98883-hyperlink-help/#findComment-505983 Share on other sites More sharing options...
sinista Posted March 31, 2008 Author Share Posted March 31, 2008 cool i think i get ya , thanks for the help mate ) Link to comment https://forums.phpfreaks.com/topic/98883-hyperlink-help/#findComment-505987 Share on other sites More sharing options...
xnowandtheworldx Posted March 31, 2008 Share Posted March 31, 2008 You could also do something along the lines of.. <?php $url=$_COOKIE["username"]; echo ("<a href=\"http://localhost/members/{$url}/{$url}.php\">My profile</a>"); ?> where you encapsulate your php variables with {} I learned this a while ago, and have been using it ever since. I like it alot better than joining all the stuff together, and in my mind makes it less confusing either way. Link to comment https://forums.phpfreaks.com/topic/98883-hyperlink-help/#findComment-506011 Share on other sites More sharing options...
sinista Posted April 1, 2008 Author Share Posted April 1, 2008 nice ty i will remember that, I just thought of another hyperlink question if im running apache server here at home and I make a link in my page like http://localhost/something.php, if click the link and it goes to something.php , the question is if i allowed people to connect to my home server would i need to change the link to httP://www.sinista.com/something.php or would they be able to use the 1st link?? Link to comment https://forums.phpfreaks.com/topic/98883-hyperlink-help/#findComment-506641 Share on other sites More sharing options...
DyslexicDog Posted April 1, 2008 Share Posted April 1, 2008 You need to do some reading about DNS, but no that localhost link will not work for anyone outside your computer. Link to comment https://forums.phpfreaks.com/topic/98883-hyperlink-help/#findComment-506646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.