Hey guys, I'm putting together a site and I need some advice on what would be simplest to do. I already made a membership process and now I want to make each member a profile. I want to make it so that a user can edit their details at account.php. And each user will have their profile that everybody sees like this. account.php?id=username. How do I do this? Anyone have any tutorials? Also, for some reason my logout doesn't work in IE. <?php include "base.php"; $_SESSION = array(); session_destroy(); ?> <meta http-equiv="refresh" content="0;index.php"> Code (markup): This is my code to logout.php. It works in Firefox but not in IE? Why? Thanks for all the help guys.
Assuming base.php includes session_start();... <?php include "base.php"; $_SESSION = array(); session_destroy(); header('Location: /index.php'); die('You shouldn\'t be here.'); PHP:
For your first question, just do an if and such. Like if(empty($_GET['id'])) { they want to edit their own profile } else { they want to view someone's profile; get the person based on $_GET['id'] } For your problem, first of all, I wouldn't use session_destroy() as I believe it's deprecated. It's recommended you either set $_SESSION itself as an empty array or set the elements in the array as null, and on top of either of those, do unset($_SESSION['element']); for them. Secondly, there is a slight problem with your meta refresh tag I believe. It should be like this: <meta http-equiv="refresh" content="0;url=index.php"> Code (markup): But yeah, as Danltn pointed it, just use a PHP header redirect.
Got it to work. Also, I have no idea what Im doing with the ?id=username thing. Do you think you could write a quick code for me? I want it when the user thats already logged in goes on account.php, he can see his details. I can get that far. But how do I make it so that another user sees what the logged in user see on his page? Thanks,
<?php if(empty($_GET['id'])) { //Put your code here for seeing their own details or whatver } else { $user_id = $_GET['id']; //They want to view another user's profile, so use $user_id to pull the specified person's information } ?> PHP:
Should I edit anything on that code? Like the UserID or something? Because if not then it gives me an error.
If you type in : account.php?id=254, you want to see someones profile .. In this case .. Fetch data from mysql where id=yourid ! If this $_GET is empty ( for example account.php ) - redirect him to a main page ..
I get this error. Parse error: syntax error, unexpected '}' in /home/content/c/e/z/user/html/account.php on line 29 Code (markup):
Then you either have a closing bracket that does not belong or you forgot to put a semi-colon at the end of the line before.. How good are you with PHP? If you're planning on making whatever it is you're making, maybe you should read more tutorials and such.
I'm just starting out. But this is the way I learn. I have learned HTML and CSS by trial and error, looking at other examples, and such. Now I'm trying to learn PHP and MySQL. Ok thanks. Got it to work EDIT: This is the code I have now. <?php if(empty($_GET['id'])) { ?> <b>Name:</b> <?=$_SESSION['Username']?> <?php }else { $user_id = $_GET['id']; ?> <b>Name:</b> <?=$_SESSION['Username']?> <?php } ?> Code (markup): If I type in www.url.com/account.php?id=3 which should be a test account, the user name still pops out as mine. and my userID is 1. How would I fix this?
Because you're still outputting the username stored in the session which would be yours (or whoever else is currently logged in and viewing it)... How do you set the $_SESSION['Username']? However you pull YOUR account info when you log in, pull the information the same way but only put it if the user's ID equals $user_id
I understand why it doesn't work. But I'm not too sure on how to retrieve the data from the MySQL table.
This is a more friendly solution to log a user out if u are using sessions if(isset($_SESSION)) unset($_SESSION); Code (markup): hope this helps!