insert a variable into link tag

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
jlgonqui
Forum Newbie
Posts: 2
Joined: Fri Apr 25, 2008 12:13 am

insert a variable into link tag

Post by jlgonqui »

I need to insert a variable into the href of the link tag to read a stylesheet. I was able to insert it and it read it ok, but ignore the format on <h1> and <div>, if I change the variable and write the correct path eveything is been formated ok. Some ideas of what Im doing wrong. Thanks so much in advanced, here is the code

Code: Select all

<?php
if (($_COOKIE[personal]=="")||($_COOKIE[loca]=="")){
    header("Location: index.html");
    exit;
}else if(($_COOKIE[personal]!="")&&($_COOKIE[loca]!="")){
    
}else{
    header("Location: index.html");
    exit;
}
$nvaloca=str_replace(' ',"_",$_COOKIE[loca]);
?>
<HTML>
<HEAD>
<TITLE>Personal</TITLE>
<?
echo "<link href=\"formato_".$nvaloca.".css\" rel=\"stylesheet\" type=\"text/css\">"
?>
</HEAD>
<BODY>
<div id="menuprincipal">
<p>Usuario:<?echo $_COOKIE[personal];?></p>
<p>Localidad:<?echo $_COOKIE[loca];?></p>
<P>MENU Personal</p>
</div>
 
<div id="doccentro">
<p>Some text</p>
</div>
</BODY>
</HTML>
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Re: insert a variable into link tag

Post by mattcooper »

The fact that hard-coding the URLs suggests to me that your cookies aren't being set properly or are expiring before they're read. Make sure you have the data you expect by printing the cookie out:

Code: Select all

 
<?php
    echo '<pre>'; print_r($_COOKIE['loca']); echo '</pre>';
 
    // and just in case this comes back empty, to confirm it's empty:
    var_dump($_COOKIE['loca']); // will probably show NULL
?>
 
I suspect you'll find a n ull value here, in which case you'll want to go look at the arguments you're passing to setcookie().

HTH :)
jlgonqui
Forum Newbie
Posts: 2
Joined: Fri Apr 25, 2008 12:13 am

Re: insert a variable into link tag

Post by jlgonqui »

Actually the values are been pass correctly. The problem is not finding the css file, the problem is it can read it and applied it, except on the div tag and h1 tag. Thanks so much.
Post Reply