10 Replies - 1330 Views - Last Post: 25 January 2009 - 10:34 AM Rate Topic: -----

#1 Justice92  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 30-September 08

Php view user

Posted 22 January 2009 - 04:37 AM

Im making a community were you can make a profile and view other users ... etc ( so basicly a social networking )

i started doing is project so i can se what techniques and the best ways to go about when coding php.
im up to the part where im making a profile page for the users.

ive seen alot of sites using
profile?=

and then the user ID.

how would i go about this and whats the best way to do this.

eny help will appreciated

I dont wont to use eny existing engines or software!

Is This A Good Question/Topic? 0
  • +

Replies To: Php view user

#2 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Php view user

Posted 22 January 2009 - 04:41 AM

What you're wanting to use is $_GET. Check that link out, it'll give you valuable information on how it operates. Be sure you validate what goes in there, however, as users can spoof their URLs and make the values of variables provided via $_GET become whatever they type. Make sure you have systems in place to prevent security breaches from that.
Was This Post Helpful? 1

#3 rmccarter721  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 139
  • Joined: 10-September 07

Re: Php view user

Posted 22 January 2009 - 09:12 AM

yea using $_GET is the best way..

But as i keep saying always validate your user input, always check it against a database and check it is in the proper format etc.
Was This Post Helpful? 0
  • +
  • -

#4 Justice92  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 30-September 08

Re: Php view user

Posted 22 January 2009 - 10:35 AM

could you please give me an example of how to use it with a query.. thanks
Was This Post Helpful? 0
  • +
  • -

#5 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Php view user

Posted 22 January 2009 - 01:25 PM

Let's say your account info is stored in a table called 'accounts'. This contains all of the information about the user's account, their profile, settings, etc. calling their page, you'll obviously want to get all of that in one pass. So, you could do something like this. Assuming your $_GET variable is 'id':

<?php

if(!is_int($_GET['id'])) {
	 die("Invalid profile ID!");
}

$query = sprintf("SELECT * FROM accounts WHERE id=%d", mysql_real_escape_string($_GET['id']));
$result = mysql_query($query) or die(mysql_error());
if($row = mysql_fetch_assoc($result)) {
	 //Profile display/setup stuff goes here.
}
else {
	 die("Profile with that ID does not exist.");
}

?>



The above is just a simple example. In reality, the finished code will probably be a bit more complex than that.
Was This Post Helpful? 0
  • +
  • -

#6 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Re: Php view user

Posted 22 January 2009 - 01:51 PM

What you will need to do is first get the id in the link if haven't already so you can add that like
echo "<a href='www.domain.com/profile='".$id."'>";



Then do on the profile page
$id = $_GET['profile'];


Then you can use that for the rest of your code to find user specific data.
Was This Post Helpful? 0
  • +
  • -

#7 paulmc91  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 18-January 09

Re: Php view user

Posted 24 January 2009 - 08:52 PM

Although many sites go for the traditional $GET I prefer the $POST although it may take a little while longer to get it working correctly it keeps the url in the address bar.

So you could have www.yoursite.com/viewprofile.php

instead of www.yoursite.com/viewprofile.php?id=1234

I prefer this but you may decide others but there's another way to do it.

PaulMc91
Was This Post Helpful? 0
  • +
  • -

#8 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Php view user

Posted 24 January 2009 - 11:08 PM

View Postpaulmc91, on 24 Jan, 2009 - 10:52 PM, said:

Although many sites go for the traditional $GET I prefer the $POST although it may take a little while longer to get it working correctly it keeps the url in the address bar.

So you could have www.yoursite.com/viewprofile.php

instead of www.yoursite.com/viewprofile.php?id=1234

I prefer this but you may decide others but there's another way to do it.

PaulMc91


The only problem is, he's doing it for a profile and wants to make it so you can view other users. Using $_GET is the only way of the two to get a permalink. $_POST would have to pass through a form submission first.

This post has been edited by Valek: 24 January 2009 - 11:08 PM

Was This Post Helpful? 0
  • +
  • -

#9 musya  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,012
  • Joined: 25-April 07

Re: Php view user

Posted 25 January 2009 - 12:07 AM

Dont forget to set a cookie or session to make sure the person is logged in and not just trying to view someone else's account.
Was This Post Helpful? 0
  • +
  • -

#10 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Re: Php view user

Posted 25 January 2009 - 02:38 AM

You can still do
viewprofile.php?id=124


Without showing the ?id=124. What you have to do is in the .htaccess file is something like.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /viewprofile.php?id=/$1 [L]



Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#11 Justice92  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 30-September 08

Re: Php view user

Posted 25 January 2009 - 10:34 AM

ye its great thanks for all your help!

i ran in to a couple of snags, so im gunna give it a break for a week and get some college work done.

but i will start next week defiant.

again THANKS for all your help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1