PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,363 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,433 people online right now. Registration is fast and FREE... Join Now!




How can i do this

 

How can i do this

nick1200

29 Jun, 2009 - 11:20 AM
Post #1

D.I.C Addict
****

Joined: 21 Mar, 2009
Posts: 551



Thanked: 6 times
My Contributions
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
CODE


        <?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 Jun, 2009 - 11:54 AM

User is offlineProfile CardPM
+Quote Post


CTphpnwb

RE: How Can I Do This

29 Jun, 2009 - 01:28 PM
Post #2

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
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"]

User is offlineProfile CardPM
+Quote Post

nick1200

RE: How Can I Do This

29 Jun, 2009 - 03:16 PM
Post #3

D.I.C Addict
****

Joined: 21 Mar, 2009
Posts: 551



Thanked: 6 times
My Contributions


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




User is offlineProfile CardPM
+Quote Post

noorahmad

RE: How Can I Do This

29 Jun, 2009 - 07:53 PM
Post #4

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
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
php
$str = "select * form profile where id=".$_SESSION['id'];

User is online!Profile CardPM
+Quote Post

nick1200

RE: How Can I Do This

30 Jun, 2009 - 04:45 AM
Post #5

D.I.C Addict
****

Joined: 21 Mar, 2009
Posts: 551



Thanked: 6 times
My Contributions
yaaa but that would show there id on the page tongue.gif

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 Jun, 2009 - 04:59 AM
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: How Can I Do This

30 Jun, 2009 - 05:04 AM
Post #6

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
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.

User is offlineProfile CardPM
+Quote Post

nick1200

RE: How Can I Do This

30 Jun, 2009 - 05:17 AM
Post #7

D.I.C Addict
****

Joined: 21 Mar, 2009
Posts: 551



Thanked: 6 times
My Contributions


so i make a new page and add

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

to it blink.gif

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


User is offlineProfile CardPM
+Quote Post

dimjaxor

RE: How Can I Do This

30 Jun, 2009 - 12:01 PM
Post #8

New D.I.C Head
*

Joined: 10 Sep, 2008
Posts: 40


My Contributions
QUOTE(nick1200 @ 30 Jun, 2009 - 05:17 AM) *

so i make a new page and add

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

to it blink.gif

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
CODE

$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.

CODE

$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
User is offlineProfile CardPM
+Quote Post

nick1200

RE: How Can I Do This

30 Jun, 2009 - 12:33 PM
Post #9

D.I.C Addict
****

Joined: 21 Mar, 2009
Posts: 551



Thanked: 6 times
My Contributions
were did u get the 1 form tho

members.php?member_id=1

the 1 lol


User is offlineProfile CardPM
+Quote Post

dimjaxor

RE: How Can I Do This

30 Jun, 2009 - 12:57 PM
Post #10

New D.I.C Head
*

Joined: 10 Sep, 2008
Posts: 40


My Contributions
QUOTE(nick1200 @ 30 Jun, 2009 - 12:33 PM) *

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)
User is offlineProfile CardPM
+Quote Post

nick1200

RE: How Can I Do This

30 Jun, 2009 - 01:06 PM
Post #11

D.I.C Addict
****

Joined: 21 Mar, 2009
Posts: 551



Thanked: 6 times
My Contributions
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
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: How Can I Do This

30 Jun, 2009 - 01:08 PM
Post #12

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
GET gets the variable from the URL.
See:
http://www.w3schools.com/PHP/php_get.asp

User is offlineProfile CardPM
+Quote Post

nick1200

RE: How Can I Do This

30 Jun, 2009 - 01:17 PM
Post #13

D.I.C Addict
****

Joined: 21 Mar, 2009
Posts: 551



Thanked: 6 times
My Contributions
i no about functions the

CODE


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


i all ready have that when they log in

tongue.gif

d.w it ill try and work it out my self thanks for your help dimjaxor smile.gif
User is offlineProfile CardPM
+Quote Post

dimjaxor

RE: How Can I Do This

30 Jun, 2009 - 01:21 PM
Post #14

New D.I.C Head
*

Joined: 10 Sep, 2008
Posts: 40


My Contributions
QUOTE(nick1200 @ 30 Jun, 2009 - 01:17 PM) *

i no about functions the

CODE


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


i all ready have that when they log in

tongue.gif

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


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
User is offlineProfile CardPM
+Quote Post

noorahmad

RE: How Can I Do This

30 Jun, 2009 - 10:48 PM
Post #15

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
i changed your header to
php

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

<?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
php

$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 smile.gif

This post has been edited by noorahmad: 30 Jun, 2009 - 10:51 PM
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 08:36PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month