Linking with variables

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
ibelimb
Forum Newbie
Posts: 18
Joined: Wed Jun 19, 2002 2:59 pm
Location: New York, USA

Linking with variables

Post by ibelimb »

Hey, this must be my like 5th post today!

I'm trying to link to another page, and i need a variable insie the href= and i cant seem to do it. Im trying ot put it inside a echo ' '; that contains other lines of HTML code to, but i cant seem to get $session to show the session id. instead PHP puts the link out like login3.php?$session and thats not how i want it, i want the session id, i have $session assigned with session_id(); so its not that.

I've tried other things too but thsoe have failed. How do i fo it?

Thanks,
Limb
gxpark
Forum Commoner
Posts: 33
Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City

Post by gxpark »

use the string concatenation operator (a dot) or use a change single quotes to double quotes, or viceversa :) it always confuses me which one automatically changes variable names for their values (I'm used to use concatenation operators like in most other languages).
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

I'm going to guess you are doing echo'' (with single quotes) and not echo"" with double quotes. if that is the case, then you need to understand that the variable is not converted to its value with the single quotes....you'll need to do string concatenation.... here are two possible solutions...

Code: Select all

//use single quotes, and concatenate  (preferred)
echo 'login3.php?'.$session;

//use double quotes
echo "login3.php?$session";
a good article on the subject can be found at http://www.webmasterbase.com/article/686
ibelimb
Forum Newbie
Posts: 18
Joined: Wed Jun 19, 2002 2:59 pm
Location: New York, USA

Post by ibelimb »

Ahh got it working, thansk i had them in ' ' not " ". Now it works, thanks!
Post Reply