geroido Posted July 18, 2008 Share Posted July 18, 2008 Hi I have a session variable that contains a string sent over from a form on the previous page. I want to concatenate another string onto the end of it. For example, the session variable holds a word like 'Galway' and I want to concatenate the string '.PHP' onto the end of it so I can include the file Galway.php on the page. I get the variable from the form with the following code: $_SESSION['town'] = $_GET['t']; Now onto the session variable 'town' I need to concatenate the string '.PHP'. Any ideas? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 $town = $_SESSION['town'].".php"; include($town); Quote Link to comment Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 Hi Thanks for that but it's still not working. I'm printing the variable to see what it contains and all I'm getting is '.php'. The session variable itself is not printing so it's not being concatenated. I have the follwing code: $_SESSION['town'] = $_GET['t']; $townjoin = $_SESSION['town'].".php"; <H2 align="center"><?print $townjoin?></H2><BR> So all I get on the webpage is .php Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted July 18, 2008 Share Posted July 18, 2008 Are you sure that $_GET['t'] has a value? Quote Link to comment Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 Yes I'm sure because I'm printing that value as well and it's appearing seperately on the webpage. I'm using the following code to do that: <H2 align="center"><?print $_SESSION['town']?></H2><BR> So I know I have the two values but they don't seem to be cocatenating. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted July 18, 2008 Share Posted July 18, 2008 Can you show us more code? Quote Link to comment Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 Hi I changed the just to test it and assign the session variable only to the new variable as in $townjoin = $_SESSION['town']; When I print $townjoin this time it's empty so there must be something wrong with assigning a session variable like this. Some small code error I suppose. Any ideas? Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted July 18, 2008 Share Posted July 18, 2008 Hi I changed the just to test it and assign the session variable only to the new variable as in $townjoin = $_SESSION['town']; When I print $townjoin this time it's empty so there must be something wrong with assigning a session variable like this. Some small code error I suppose. Any ideas? Are you calling session_start() at the beginning of your code? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 Make sure session_start() is at the top of every single page. Quote Link to comment Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 $_SESSION['town'] = $_GET['t']; $townjoin = $_SESSION['town'].".php"; <H2 align="center"><?print $_SESSION['town']?></H2><BR> <H2 align="center"><?print $townjoin?></H2><BR> This is the code. I get the string from the form ($_GET['t']) and I assign it to the session variable. This works because when I print the session variable it appears on the web page. However when I try to concatenate that onto '.php' and store the result in $townjoin all that prints is '.php'. Don't know what's wrong Quote Link to comment Share on other sites More sharing options...
geroido Posted July 18, 2008 Author Share Posted July 18, 2008 Yes I'm calling session_start; at the top Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 18, 2008 Share Posted July 18, 2008 Why do you need to store it in a session? Why not use it straight from $_GET? $townjoin = $_GET['t'].".php"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.