PHP Help - What do you suggest?

Discussion in 'PHP' started by Pixel T., Dec 27, 2008.

  1. #1
    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.
     
    Pixel T., Dec 27, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    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:
     
    Danltn, Dec 27, 2008 IP
  3. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    zerxer, Dec 27, 2008 IP
  4. Pixel T.

    Pixel T. Well-Known Member

    Messages:
    1,205
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    170
    #4
    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,
     
    Pixel T., Dec 27, 2008 IP
  5. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?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:
     
    zerxer, Dec 27, 2008 IP
  6. Pixel T.

    Pixel T. Well-Known Member

    Messages:
    1,205
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    170
    #6
    Should I edit anything on that code? Like the UserID or something? Because if not then it gives me an error.
     
    Pixel T., Dec 27, 2008 IP
  7. farad

    farad Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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 ..
     
    farad, Dec 27, 2008 IP
  8. Pixel T.

    Pixel T. Well-Known Member

    Messages:
    1,205
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    170
    #8
    I get this error.

    Parse error: syntax error, unexpected '}' in /home/content/c/e/z/user/html/account.php on line 29
    Code (markup):
     
    Pixel T., Dec 28, 2008 IP
  9. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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.
     
    zerxer, Dec 28, 2008 IP
  10. Pixel T.

    Pixel T. Well-Known Member

    Messages:
    1,205
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    170
    #10
    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?
     
    Pixel T., Dec 28, 2008 IP
  11. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #11
    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
     
    zerxer, Dec 28, 2008 IP
  12. Pixel T.

    Pixel T. Well-Known Member

    Messages:
    1,205
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    170
    #12
    I understand why it doesn't work. But I'm not too sure on how to retrieve the data from the MySQL table.
     
    Pixel T., Dec 28, 2008 IP
  13. hackfanatic

    hackfanatic Peon

    Messages:
    29
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    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!
     
    hackfanatic, Dec 29, 2008 IP