Closed Thread
Results 1 to 6 of 6

Thread: Multi-User Profile Pages

  1. #1
    matrob's Avatar
    matrob is offline Newbie
    Join Date
    Jul 2010
    Location
    Ruston, LA
    Posts
    12
    Rep Power
    0

    Multi-User Profile Pages

    I currently have a site that allows users to log and view personal workout information. When the user logs in, they are directed to their profile page. Currently, users have zero access to information by other users, so when they are directed to .../profile.php, the page is built using information from $_SESSION['user']. However, I am trying to change my site to allow users to view limited profiles of other users, with the eventual ability to add friends, send messages, etc., much like most forums or social networking sites. I see the url's in these sites being something similar to .../profile.php?user=381752 with the number being that user's user_id. This also seems similar to the php $_GET function, but as of yet I have not been able to figure out how to direct the user to the desired page... Any help would be appreciated.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,087
    Blog Entries
    7
    Rep Power
    42

    Lightbulb Re: Multi-User Profile Pages

    $_GET is not a function, but a global array containing all parameters sent through the URL. so if you have as your example, $_GET['user'] would contain the number 381752. then just query your database to show that user's info instead. something which could look like this:
    Code:
    // try if a user number is provided by URL
    if ($_GET['user'] != "") {
      
    // If so, query that user and present limited info
      
    $result mysql_query("SELECT * FROM users WHERE id = '"
        
    .mysql_real_escape_string($_GET['user'])."'");
      
    $limited true;
    } else {
    // If not, show the users own profile...
      
    $result mysql_query("SELECT * FROM users WHERE id = '"
        
    .mysql_real_escape_string($_SESSION['user'])."'");
     
    $limited false;
    }
    // check if a user with that ID was found
    if ($row mysql_fetch_array($result) {
      
    // it was, output whatever
      
    echo $row['username']."s profile";
      echo 
    $row['username']." is ".$row['age']." years old";
      if (!
    $limited) {
      
    // this is only on users own profile
        
    echo "account is valid until ".$row['paid-until'];
      }
    } else {
      
    // no user with that id was found
      
    echo "No such user was found";

    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  4. #3
    matrob's Avatar
    matrob is offline Newbie
    Join Date
    Jul 2010
    Location
    Ruston, LA
    Posts
    12
    Rep Power
    0

    Re: Multi-User Profile Pages

    Thank you. I think what I'm confused about is how to reach the user profile page. I know I could have a textbox in a form with a method="get" and use $_GET['textbox name'] but I don't know how else to do it. Obviously, I'm new to php.

  5. #4
    Join Date
    Jun 2010
    Location
    Vancouver, Eh.
    Posts
    4,027
    Blog Entries
    7
    Rep Power
    39

    Re: Multi-User Profile Pages

    $_GET is purely accessable through the URL sent to the PHP script.

    profile.php?user=381752 will fill the variable $_GET['user'] with the value 381752 in the PHP script. You can then use Orjan's example and access a user's profile if the $_GET is set. If not then display their own profile.
    Be sure to read the updated FAQ || Health is achieved through 10,000 different steps.
    A textual description can be only part of your question, be sure to provide sample results, errors and your platform in the appropriate forums while asking.

  6. #5
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,087
    Blog Entries
    7
    Rep Power
    42

    Re: Multi-User Profile Pages

    you can easily also put an url as a normal link using get... like this:
    HTML Code:
    <a href="index.php?user=381752">Link to user's profile</a>
    which alsoc of course could be generated by php: (assuming the user's db info is already fetched in $row)
    Code:
    echo '<a href="index.php?user='.$row['id'].'">'.$row['name'].'</a>'
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  7. #6
    matrob's Avatar
    matrob is offline Newbie
    Join Date
    Jul 2010
    Location
    Ruston, LA
    Posts
    12
    Rep Power
    0

    Re: Multi-User Profile Pages

    Ah got it working now. Thank you both!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Multi user access login
    By iswan in forum Visual Basic Programming
    Replies: 3
    Last Post: 10-22-2011, 02:17 AM
  2. Administrotor pages for user management
    By zhenyaa in forum ASP, ASP.NET and Coldfusion
    Replies: 1
    Last Post: 08-19-2010, 09:06 AM
  3. Help profile settings
    By ahmed in forum C# Programming
    Replies: 5
    Last Post: 12-03-2008, 01:12 PM
  4. Replies: 12
    Last Post: 03-15-2008, 04:34 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts