Acidic.Saliva Posted July 2, 2006 Share Posted July 2, 2006 I know how to handle $_GET and $_POST with HTML forms, but say someone logs in on my site and it shows their name as a greeting "Hello (username here)!", but I also want it to show up on all the other pages as long as they're logged in. How can I keep sending the information to the new page when they click a link? Quote Link to comment https://forums.phpfreaks.com/topic/13487-_get-and-_post-question/ Share on other sites More sharing options...
corbin Posted July 2, 2006 Share Posted July 2, 2006 a session or a dynamic URL Quote Link to comment https://forums.phpfreaks.com/topic/13487-_get-and-_post-question/#findComment-52180 Share on other sites More sharing options...
Acidic.Saliva Posted July 2, 2006 Author Share Posted July 2, 2006 lol, I'm kind of a noob, how would I do either of those?EDIT: Oh wait, could I just say like echo "<a href="myphppage.php?username=$username>"? Quote Link to comment https://forums.phpfreaks.com/topic/13487-_get-and-_post-question/#findComment-52184 Share on other sites More sharing options...
JamesRyzon Posted July 2, 2006 Share Posted July 2, 2006 [quote author=Acidic.Saliva link=topic=99222.msg390688#msg390688 date=1151870475]lol, I'm kind of a noob, how would I do either of those?EDIT: Oh wait, could I just say like echo "<a href="myphppage.php?username=$username>"?[/quote]You could do that but then in theory if you arent Securing it anyone could just type into their bar http://path.to/yoursite.php?username=whateverTo set a session variable youll need to first[code] session_start(); [/code] on the page you want to use sessions on.Then its as simple as [code]$_SESSION['username'] = $someformofusername;[/code]and calling $_SESSION['username'] in your code later Quote Link to comment https://forums.phpfreaks.com/topic/13487-_get-and-_post-question/#findComment-52187 Share on other sites More sharing options...
Acidic.Saliva Posted July 2, 2006 Author Share Posted July 2, 2006 aha, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/13487-_get-and-_post-question/#findComment-52194 Share on other sites More sharing options...
avo Posted July 2, 2006 Share Posted July 2, 2006 HI This may help you out and addapt the code to suite first page "LOGIN FORM PAGE"[quote]session_start ();include ('includes/dbconfig.php') ; // if logout == trueif($_GET['Logout'] == "true"){ unset($_SESSION); session_destroy(); header('Location: login.php');} if (isset($_POST['btn_login'])){ mysql_connect ($dbhost, $dbuser, $dbpass); mysql_select_db ($dbname) or die ( mysql_error ()); $sql="SELECT * FROM users WHERE username = '".$_POST['txt_username']."' AND password = '".md5($_POST['txt_password'])."'"; $result=mysql_query($sql) or die (mysql_error() ); if(mysql_num_rows($result) > 0){ $row=mysql_fetch_assoc($result) or die (mysql_error() );//GET INFORMATION FROM DB ASSING TO SESSION $_SESSION['level']=$row['level']; $_SESSION['real_name']=$row['real_name']; } elseif ($_POST['txt_username'] =="" or $_POST['txt_password'] ==""){ $input_error = '<p align="center" class=style8>No Username or Password Entered!</p>' ;//nothing in pass or user box } else { $input_error = '<p align="center" class=style8>No such Username or Password Found!</p>' ;// no user in db }}//WHAT EVER LEVEL RECIVED FROM DB IN ASSOC WITH USERNAME ASSIGN SESSION HERE AND RE-DIRECT USERif($_SESSION['level']=="admin") { $_SESSION['admin']="true" ; header('Location: admin_header.php');}elseif($_SESSION['level']=="limited1"){ $_SESSION['level1']="true" ; header('Location: user_header.php');}elseif($_SESSION['level']=="limited2"){ $_SESSION['level2']="true" ; header('Location: user_header2.php');}elseif($_SESSION['level']=="limited3"){ $_SESSION['level3']="true" ; header('Location: user_header3.php');}else//IF SESSION == FALSE ECHO FORM BELLOW AGAIN{ [/quote]that code will allow 4 different users to be redirected to differrent headers deppendent on name in level coloum in databasein the last else put your html code Login form code to be echoed with this example you will need to create 4 different headers to be redirected to ok in all the other pages at the top you will need to putTHIS ONE IS FOR ADMIN[quote]session_start();if($_SESSION['admin'] == "true"){//ALL YOUR HEADER CODE }[/quote]FOR LEVEL ONE AUTH[quote]session_start();if($_SESSION['level']=="limited1") {//all your code}?>[/quote]FOR LEVEL TWO AUTH [quote]session_start();if($_SESSION['level1']=="limited2") {//all your code}?>[/quote]FOR LEVEL THREE AUTH [quote]session_start();if($_SESSION['leve2']=="limited3") {//all your code}?>[/quote]now if you create a logout button on your page use direct in the url login.php?logout=true(login.php)is the page name the main logout code is in and the password and username html text boxes arebut you can adapt this anyway you would like this is one i wrote for a stores database and still doing the pages for it hope this helps you out Quote Link to comment https://forums.phpfreaks.com/topic/13487-_get-and-_post-question/#findComment-52201 Share on other sites More sharing options...
Acidic.Saliva Posted July 2, 2006 Author Share Posted July 2, 2006 Hmm... I did just like you said,session_start() before everything and I stored the username. It works fine if I call $_SESSION['username'] on the same page, but when I move the the linked page, it doesn't work. No error message, just doesn't print it out. Is there something I'm supposed to do to enable it on the other page? Quote Link to comment https://forums.phpfreaks.com/topic/13487-_get-and-_post-question/#findComment-52228 Share on other sites More sharing options...
avo Posted July 2, 2006 Share Posted July 2, 2006 Hi Did you do session_start () on the other page?on the next page to test it out do [code]session_start() ;echo $_SESSION['name'];[/code]you should then have what ever that session is holding in the next page.hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/13487-_get-and-_post-question/#findComment-52230 Share on other sites More sharing options...
Acidic.Saliva Posted July 2, 2006 Author Share Posted July 2, 2006 Yep! That Did It! Thanks! I thought that if you did session_start() again, it would restart it and wipe everything out, but I guess I was wrong. Quote Link to comment https://forums.phpfreaks.com/topic/13487-_get-and-_post-question/#findComment-52237 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.