Jump to content

hyperlink help :)


sinista

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.