Page 1 of 1

insert a variable into link tag

Posted: Fri Apr 25, 2008 12:40 am
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>

Re: insert a variable into link tag

Posted: Fri Apr 25, 2008 9:35 am
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 :)

Re: insert a variable into link tag

Posted: Fri Apr 25, 2008 3:24 pm
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.