Jump to content

echo dynamic link


tomm098

Recommended Posts

Hey all I have a problem with echoing a PHP dynamic link. This is the link i need to echo. It works fine as a HTML link but as soon as i put it in the PHP echo code it stuffs up. I think it needs a different syntax or something.

 

<a href="userstats.php?User=<?php echo ($_COOKIE ['Username']) ?>"><?php echo ($_COOKIE['Username']) ?></a>

 

I must PHP echo it like so:

<?php echo "THE LINK ABOVE"

 

 

any help would be greatly appreciated.. thanks

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/
Share on other sites

Please post a few lines before and after that line. The error could be in a previous PHP line, but the parser couldn't see that until it hit this line.

 

No, since the "echo" is terminated by the closing "?>" that line doesn't need a ";"

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1055987
Share on other sites

This is my entire code, but im fairly sure its the link that is the problem because it works fine until i replace the first echo. I'm trying to replace the "($_COOKIE['Username']) after //user is logged in. with the first <a href link

 

<p><a href="userstats.php?User=<?php echo ($_COOKIE ['Username']) ?>"><?php echo ($_COOKIE['Username']) ?></a></p>
    <p>
    <?php
    if($_SESSION['Username'] || $_COOKIE['Username'])
{
//user is logged in
echo ($_COOKIE['Username'])."<br /"."<a href=\"Logout.php\">Logout</a>";

}
else
{
//user is not logged in
echo "<a href=\"/logreg/Login.php\">Login</a>"."<br />"."<a href=\"/logreg/Registration.php\">Register</a>";
}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1055999
Share on other sites

http://www.php.net/manual/en/tokens.php

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home2/whatsong/public_html/test.php on line 246

 

makes me believe you tried:

 

<?php echo "<a href="userstats.php?User=<?php echo ($_COOKIE ['Username']) ?>"><?php echo ($_COOKIE['Username']) ?></a>" ?>

 

Edit: remove the space after $_COOKIE

Link to comment
https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1056001
Share on other sites

I dont think i have a script. but this is what was returned

 

Array

(

    [__utma] => 213566930.929732667496323600.1250559715.1273507737.1273513206.669

    [__utmb] => 213566930.12.10.1273513206

    [__utmc] => 213566930

    [__utmz] => 213566930.1272378641.588.9.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=the boat that rocked song

    [userId] => 59

    [username] => tomm098

    [_csuid] => 4a36424d10dbcd31

    [phpSESSID] => gcjcbqlbjlo8vmfjnueeqlgf17

    [user] => MM_Username

)

 

Link to comment
https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1056024
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.