turnej Posted April 8, 2011 Share Posted April 8, 2011 Hi I have a page which I have password protected via my hosting cpanel and given every user a different id and password, is there anyway I can utilise the name of the person logged in and display it on my site - so for example when a particular person logs in it will say hello [[name]], I also want to capture the users name to post to a my sql table - any help gratefully received. Link to comment https://forums.phpfreaks.com/topic/233130-hello-name/ Share on other sites More sharing options...
nethnet Posted April 8, 2011 Share Posted April 8, 2011 Use sessions. Include this at the top of every page: <?php session_start(); ?> Then, when a user logs in, set a session variable. <?php $_SESSION['name'] = $name // Or whatever you have it named ?> That variable will "carry over" onto every page as long as you have session_start() at the top. <?php echo "Hello, {$_SESSION['name']}!"; ?> Link to comment https://forums.phpfreaks.com/topic/233130-hello-name/#findComment-1198950 Share on other sites More sharing options...
turnej Posted April 8, 2011 Author Share Posted April 8, 2011 Hi Thanks for your reply when you say 'whatever you have it named' is this the user field? I don't really follow - How do I tell the page where to get the variable from i.e. the user name for log in from my cpanel? Sorry I am sure this is very simple I am a complete beginner and just trying to get started with php thanks again Link to comment https://forums.phpfreaks.com/topic/233130-hello-name/#findComment-1198960 Share on other sites More sharing options...
nethnet Posted April 8, 2011 Share Posted April 8, 2011 Well, it would be the same thing that is used to query your database for login. Do you already have that part written? Include any code you already have for the login script, and I'll try to modify it to allow what you want. Link to comment https://forums.phpfreaks.com/topic/233130-hello-name/#findComment-1198984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.