14 Replies - 735 Views - Last Post: 30 June 2009 - 11:48 PM Rate Topic: -----

#1 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

How can i do this

Posted 29 June 2009 - 12:20 PM

i want to try and make it so when user log in it goes to

mysite.com/membersid=there_id


i have got it on my other site but i didnt make it so don't know how it works


any 1 knows what its called or how i could do it


( sorry for posting a lot of stuff to day )


My Login Page

		<?php
session_start();
// dBase file
include "dbConfig.php";

if ($_GET["op"] == "login")
 {
 if (!$_POST["username"] || !$_POST["password"])
  {
  die("You need to provide a username and password.");
  }
 
 // Create query
 $q = "SELECT * FROM `dbUsers` "
  ."WHERE `username`='".$_POST["username"]."' "
  ."AND `password`='".$_POST["password"]."' "
  ."LIMIT 1";
 // Run query
 $r = mysql_query($q);

 if ( $obj = @mysql_fetch_object($r) )
  {
  // Login good, create session variables
  $_SESSION["valid_id"] = $obj->id;
  $_SESSION["valid_user"] = $_POST["username"];
  $_SESSION["valid_time"] = time();

  // Redirect to member page
  Header("Location: members.php");
  }
 else
  {
  // Login not successful
  die("Sorry, could not log you in. Wrong login information.");
  }
 }
else
 {
//If all went right the Web form appears and users can log in
 echo "<form action=\"?op=login\" method=\"POST\">";
 echo "Username: <input name=\"username\" size=\"15\"><br />";
 echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
 echo "<input type=\"submit\" value=\"Login\">";
 echo "</form>";
 }
?>





i just wanna try and make it so it goes to mysite.com/membersid=there id

This post has been edited by nick1200: 29 June 2009 - 12:54 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How can i do this

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3063
  • View blog
  • Posts: 10,741
  • Joined: 08-August 08

Re: How can i do this

Posted 29 June 2009 - 02:28 PM

You could do something like
header('Location: members.php?memberid=".$obj->id);
but I'd just use the session variables you've already set up, when I got to the members.php page:
$_SESSION["valid_id"]
$_SESSION["valid_user"]
$_SESSION["valid_time"]
Was This Post Helpful? 0
  • +
  • -

#3 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: How can i do this

Posted 29 June 2009 - 04:16 PM

yaa thats the easiest way

some 1 said i had to do a mod rewrite

which seems hard

that way you just said can i like type any id in ?

cus i was gonna make 1 page thats different for every 1

like ig i type mysite/id=1

then it would show id 1s profile on that page

if i go to mysite/id=2

it would show ids 2 profile on that page
Was This Post Helpful? 0
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: How can i do this

Posted 29 June 2009 - 08:53 PM

Quote

You could do something like
header('Location: members.php?memberid=".$obj->id);
but I'd just use the session variables you've already set up, when I got to the members.php page:
$_SESSION["valid_id"]
$_SESSION["valid_user"]
$_SESSION["valid_time"]


as Ctphpnwb Explained You can use Sessions Every Where so you can use $_SESSION['id'] in your query to get the Logged in User Profile
$str = "select * form profile where id=".$_SESSION['id'];

Was This Post Helpful? 0
  • +
  • -

#5 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: How can i do this

Posted 30 June 2009 - 05:45 AM

yaaa but that would show there id on the page :P

in wanna try and make it so its in the url

cus im tyring to make it so when some 1 goes to

mysite.com/members=user_id

were user_id is they ent a friend id and it will go to there friend profile

This post has been edited by nick1200: 30 June 2009 - 05:59 AM

Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3063
  • View blog
  • Posts: 10,741
  • Joined: 08-August 08

Re: How can i do this

Posted 30 June 2009 - 06:04 AM

So do the same thing with the friend id, or since you're having them enter that id then maybe your form's action should go directly to the page that shows the a person's profile.
Was This Post Helpful? 0
  • +
  • -

#7 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: How can i do this

Posted 30 June 2009 - 06:17 AM

so i make a new page and add

header('Location: members.php?memberid=".$obj->id);

to it :blink:

i am trying to make 1 page that would be different for every 1 lol

like if they log in it goes to this 1 page and shows there profile

but then has well if they type in some 1 elses id that page would show the profile of that person
Was This Post Helpful? 0
  • +
  • -

#8 dimjaxor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 10-September 08

Re: How can i do this

Posted 30 June 2009 - 01:01 PM

View Postnick1200, on 30 Jun, 2009 - 05:17 AM, said:

so i make a new page and add

header('Location: members.php?memberid=".$obj->id);

to it :blink:

i am trying to make 1 page that would be different for every 1 lol

like if they log in it goes to this 1 page and shows there profile

but then has well if they type in some 1 elses id that page would show the profile of that person



members.php?member_id=1
$member = $_GET['member_id']


That will get the member ID, then you just use that ID to get info from the database then output it to the page. EX.

$member = $_GET['member_id'];
$sql = "SELECT * FROM members WHERE id = '$member'";
$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result)){
	echo 'Member ID: '.$row['id'].'</br>';
	echo 'Member Name: '.$row['name'].'</br>';
	echo 'Member Email: '.$row['email'].'</br>';
}



I have a feeling that this will still be confusing, you need to do some reading up on php before you venture into anything using databases/sessions.
PHP $_GET
PHP Mysql
PHP Sessions
Was This Post Helpful? 0
  • +
  • -

#9 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: How can i do this

Posted 30 June 2009 - 01:33 PM

were did u get the 1 form tho

members.php?member_id=1

the 1 lol
Was This Post Helpful? 0
  • +
  • -

#10 dimjaxor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 10-September 08

Re: How can i do this

Posted 30 June 2009 - 01:57 PM

View Postnick1200, on 30 Jun, 2009 - 12:33 PM, said:

were did u get the 1 form tho

members.php?member_id=1

the 1 lol


I got it from you, you said you want to be able to type in members.php?member_id=(A NUMBER)
Was This Post Helpful? 0
  • +
  • -

#11 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: How can i do this

Posted 30 June 2009 - 02:06 PM

yaa into the url so i make a page with

members.php?member_id=(A NUMBER)

that on :S

that wont make it so when a user types in a number in that gap it goes to there profile tho lol
Was This Post Helpful? 0
  • +
  • -

#12 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3063
  • View blog
  • Posts: 10,741
  • Joined: 08-August 08

Re: How can i do this

Posted 30 June 2009 - 02:08 PM

GET gets the variable from the URL.
See:
http://www.w3schools...PHP/php_get.asp
Was This Post Helpful? 0
  • +
  • -

#13 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: How can i do this

Posted 30 June 2009 - 02:17 PM

i no about functions the


Welcome <?php echo $_GET["fname"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old! 



i all ready have that when they log in

:P

d.w it ill try and work it out my self thanks for your help dimjaxor :)
Was This Post Helpful? 0
  • +
  • -

#14 dimjaxor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 10-September 08

Re: How can i do this

Posted 30 June 2009 - 02:21 PM

View Postnick1200, on 30 Jun, 2009 - 01:17 PM, said:

i no about functions the


Welcome <?php echo $_GET["fname"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old! 



i all ready have that when they log in

:P

d.w it ill try and work it out my self thanks for your help dimjaxor :)


The members.php is a dynamic page that loads the information.

if you type members.php?member_id=1 it will query the database get the needed info from the member with the id of 1 and display it on the page.

If you type members.php?member_id=2 it will query the database and get the info for the member with the id of 2 and display it.

Good Luck
Was This Post Helpful? 0
  • +
  • -

#15 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: How can i do this

Posted 30 June 2009 - 11:48 PM

i changed your header to
Header("Location: members.php?id=".$obj->id); // Where $obj-> is your logged in user id number from database



and you full code looks like this:
<?php
session_start();
// dBase file
include "dbConfig.php";

if ($_GET["op"] == "login")
 {
 if (!$_POST["username"] || !$_POST["password"])
  {
  die("You need to provide a username and password.");
  }
 
 // Create query
 $q = "SELECT * FROM `dbUsers` "
  ."WHERE `username`='".$_POST["username"]."' "
  ."AND `password`='".$_POST["password"]."' "
  ."LIMIT 1";
 // Run query
 $r = mysql_query($q);

 if ( $obj = @mysql_fetch_object($r) )
  {
  // Login good, create session variables
  $_SESSION["valid_id"] = $obj->id;
  $_SESSION["valid_user"] = $_POST["username"];
  $_SESSION["valid_time"] = time();

  // Redirect to member page
  Header("Location: members.php?id=".$obj->id);
  }
 else
  {
  // Login not successful
  die("Sorry, could not log you in. Wrong login information.");
  }
 }
else
 {
//If all went right the Web form appears and users can log in
 echo "<form action=\"?op=login\" method=\"POST\">";
 echo "Username: <input name=\"username\" size=\"15\"><br />";
 echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
 echo "<input type=\"submit\" value=\"Login\">";
 echo "</form>";
 }
?>



for show data from database
$str = "select * from profile where userid=".$_GET['id'];
$query = mysql_query($str)or die(mysql_error());
while($fetch = mysql_fetch_assoc($query))
{
	echo $fetch['colname'];
}

Hope it Help You :)

This post has been edited by noorahmad: 30 June 2009 - 11:51 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1