Jump to content

[SOLVED] unique reference to a page


ghqwerty

Recommended Posts

OK, let's say you have stats.php and you want to pass a variable into it:

 

Let's say you direct a user to blahblahblah/stats.php?user=blah because their username is "blah."

 

stats.php

<?php
if (!isset($_REQUEST['user'])) die("No user!");
$username = $_REQUEST['user'];

echo "User name is $username!";
?>

 

Then, going to blahblahblah/stats.php?user=blah would display:

User name is blah!

 

That help?

ok just tried it a bit

 

im going to do it with user id's instead of name for less errors

 

im getting confused

 

please go through it again in REALY dumb talk lol

as in where to put it

 

also

where you have $_REQUEST['user']

 

what should the user bit be replaced with ??

OK, if you have a page's URL, let's say http://example.com/somepage.php, you can pass variables into it by listing them after a ? and separating them with a &. So, let's say you want to pass one variable in called "somevar1" and you want it to equal "blah."

 

After the http://example.com/somepage.php just add a ? and somevar1=blah, and you get http://example.com/somepage.php?somevar1=blah. If you wanted to pass the same "somevar1" and a new one, maybe "anothervar1" and make it equal "anotherblah," you would do this: http://example.com/somepage.php?somevar1=blah&anothervar1=anotherblah.

 

Each variable passed in after the ? will be added to the $_REQUEST array. So, $_REQUEST['somevar1'] will give you a value of "blah" and $_REQUEST['anothervar1'] will equal "anotherblah."

 

To test this, create a page on your site called "test.php" and put ONLY this inside it:

<?php
print_r($_REQUEST);
?>

 

Now, navigate to that page and add variables to the URL string and you should see the results.

 

Try something like: http://<yoursite>.com/test.php?somevar1=blah&anothervar1=anotherblah

Array ( [user] => hello

[phpSESSID] => 0d015c1ac8d00d8144c4c372dfc65c10 )

thats what i get

so how would i factor that into a stats page

would i have to do the query based on the variable up top??

how would i do that

man i feel like ive gone 10 spaces backwards in php

i used to grasp it well easily and now i feel like im just starting again

what i want to do is do
localhost/stats.php?uid=$usersid

so would i get that $userid from the session i create when i log in ??

also where i have the query to get the stats would i have to do

$who = "select * from members where id = ' " . $_request['uid'] . " ' ";

 

???i think im getting it :)

Not sure what you're asking for. If you have the userid in a session variable, why do you need to pass it into another page?!?

 

To retrieve your uid variable that you've passed with localhost/stats.php?uid=$usersid, you'll need to reference the $_REQUEST['uid'] variable.

i dont think you need a code to check for that.

i think your looking for a code to check if its your username so you can edit it and stuff if it is your page?

 

all you need is something similar to.

<?php
$queryposts = "SELECT posts FROM table WHERE id = '$_REQUEST['uid']"
$posts = mysql_query($queryposts);
echo "Posts: " . $posts;

?>

OK, so for each of your links, let's say your code is this:

 

<?php
$query = "SELECT username, uid FROM users...";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)){
 echo "<a href='users.php?uid={$row['uid']}'>{$row['username']}</a><br>";
}
?>

 

Then, users.php:

<?php
$uid = $_REQUEST['uid'];
$query = "SELECT * FROM users WHERE uid = '$uid'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
print_r($row);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.