When someone clicks a link on my site, they are sent to a page which: adds the click to a database selects the real link redirects the visitor using the real link mysql_query("UPDATE table SET column = column+1 WHERE id=$id"); $href = "SELECT link FROM table WHERE id=$id"; $qry = mysql_query($href); list($href)=mysql_fetch_row($qry); header("Location:$href\n"); PHP: The problem is, my real links ($href) contain a variable, too: http://www.example.com?id=$var Will having a variable ($var) inside another variable ($href) work?
Thanks for the response! Points added to your account. One quick thing though . . . Are you absolutely sure about this? It's very important that I get this right first time round. And why did you get rid of "\n". Can't I use that in there? header("Location: " .eval($href\n)); PHP:
Always test before implementation: $href = 'page.php?id=$test'; $test = '23'; echo eval($href); PHP: Why would you need a newline character at the end? After the location header, the page changes so you won't be able to send other headers. Peace,
if all you need to do is append an id to the data pulled from the DB, why can't you just do $href .= "?id=$var" or is the output from the DB already going to be referencing it from the DB? i have to say such an approach as the eval suggested here is far from practical and I believe you may simply not be communicating what you are trying to achieve correctly--unless you REALLY record URLs like '/page.php?id=$var' in there. its far more practical to return just 'page.php' and then add the param afterwards or append within the header function itself. and yes, you can have whatever combos of variables within variables: $foo = "bar"; $bar = "foo$bar"; // foobar make sure you use double quotes " - with single ' it will be literal and just make it print the 'foo$bar'.
Doesn't work, dude: Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\xampp\ctyi\testing.php(7) : eval()'d code on line 1 Code (markup): However, I got it to work like this: <?php $href = 'page.php?id=$test'; $test = '23'; eval("\$href = \"$href\";"); echo $href; ?> PHP: Thanks for the guidance!
you wil use your own type of variables int href and replace them with original ones for example $href = 'http://www.example.com/index.php?id=[id]&p=[p]&s='; $href =str_replace('[id]' , $id , $href); $href =str_replace('[p]' , $p , $href); $href =str_replace('' , $s , $href); now header("Location:$href\n"); will wrok