runnerjp Posted November 27, 2007 Share Posted November 27, 2007 how can i $_GET['username'] from going through a link? if (isset($_GET['username'])) { $username = mysql_real_escape_string($_GET['username']); $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if ((mysql_num_rows($result)) == 1) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; } else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } } else { echo "No ID passed"; } ?> this is what i use if i users goes by e.g mysite.com/members/username Quote Link to comment Share on other sites More sharing options...
todding01 Posted November 27, 2007 Share Posted November 27, 2007 Change to $_POST[] Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 but would that wouldnt get the username from the link ? Quote Link to comment Share on other sites More sharing options...
obsidian Posted November 27, 2007 Share Posted November 27, 2007 What you're asking about is doing a mod_rewrite. Since you are passing in a username via a path structure (ie, "/members/<username>"), you cannot access it directly via $_GET. Are you using a mod_rewrite? You'll most likely need to parse your URL to get it instead. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 yes im using a mod_rewrite RewriteRule ^([^/.]+)/?$ members/profile.php?username=$1 how would i go about phrseing my url ... sorry for playing dumb lol Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 27, 2007 Share Posted November 27, 2007 try this out. <?php $link = $_SERVER['PHP_SELF']; $pos = strrpos($link,'/')+1; $len = strlen($link); echo substr($link,$pos,$len); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 how would i go about phrseing my url ... sorry for playing dumb lol Doing what with your url? And will you please stop opening new threads in relation to this same question! Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 thorpe i had last thread as solved...sorry will keep this 1 open... well i have got my profile working but if i wanted the user to view there own profile by clicking a link saying view my profile on a page example.. wwww.mywebsite.com/members/index.php to get to the profile on www.mywebsite.com/members/profile.php does that make better sence? Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 does that make better sence? Not really. All you need do is make a link to the page that displays the users profile. I'm just not sure I see where your stuck. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 27, 2007 Share Posted November 27, 2007 runnerjp did you see the code i posted? that code would look at mysite.com/members/username get the username and you can put it to a variable and do your search. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 hey corillo can you explain what the script is ding please so i know how to use it Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 Honestly, you need to descibe your problem better. corrilo posted a workaround to mod_rewrite. Is the mod_rewrite rule your problem? What exactly are you wanting to do? Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 27, 2007 Share Posted November 27, 2007 i think you should listen to thrope first but what the scrip do is. <?php //take the link from the current page $link = $_SERVER['PHP_SELF']; // this finds the last instance of slash / so no matter how mant slashes this will look for the last the one is added becuase it counts upto the last slash so +1 will add the last slash to the count $pos = strrpos($link,'/')+1; //this gets the length of characters in the link $len = strlen($link); // this take 3 paremeter the first is the normal link the second would be what you got form post and last what you got from length, check php.net for better descriptions. substr($link,$pos,$len); //the outcome of this is whatever is after the last / ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 sorry finding it really hard to explain so here i go ok so when a user wants to view a profile they would go to www.runningprofiles.com/members/thereusername this would view the username entred profile. but if a users logs into their own account and after updating their profile wants to view their own profile how ca i do it so they c get to this page www.runningprofiles.com/members/thereusername Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 Ok. Assuming your users are logged in using sessions, you can make your profile.php have some defaults. <?php session_start(); // see if a name was passed via the url. if (isset($_GET['username'])) { $username = mysql_real_escape_string($_GET['username']); } elseif (isset($_SESSION['username'])) { $username = $_SESSION['username']; } else { die("No profile to search for"); } $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; } else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 hey can u help me lol ok i cant seem to add the 2 together.. with your code abouve with the get user session i have function get_username ( $id ) { global $db; $query = "SELECT `Username` FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $id ); if ( $db->RecordCount ( $query ) == 1 ) { $row = $db->getRow ( $query ); return $row->Username; } else { return FALSE; } } Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 <?php session_start(); // see if a name was passed via the url. if (isset($_GET['username'])) { $username = mysql_real_escape_string($_GET['username']); } elseif (isset($_SESSION['username'])) { $username = $_SESSION['username']; } else { die("No profile to search for"); } $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; } else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> so its easy for u guys to see Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 27, 2007 Share Posted November 27, 2007 if your using this: RewriteRule ^([^/.]+)/?$ members/profile.php?username=$1 all you need to do is this: <?php echo $_GET['username']; ?> If that doesn't work, then your RewriteRule is incorrect. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 it does work is you go to www.mywebsite.com/members/admin but what if i want to do a link from the site from the users page... need to add the session in to get the user name Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 27, 2007 Share Posted November 27, 2007 Like this? <?php echo'<a href="http://mywebsite.com/members/'.$_GET['username'].'">'.$_GET['username'].'</a>'; ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 humm no... could i not use http://www.mywebsite.com/members/<?. get_username ( $_SESSION['user_id'] ) . ?> as a link? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 <a href="<?php echo . get_username ( $_SESSION['user_id'] ) . ?>">http://runningprofiles.com/members/<?php echo . get_username ( $_SESSION['user_id'] ) . ;?> tried this and get error Parse error: syntax error, unexpected '.', expecting ',' or ';' in /home/runningp/public_html/members/index.php on line 6 yet i think i finished it right ?? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 27, 2007 Author Share Posted November 27, 2007 ok done it ...thanks for help guys Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 27, 2007 Share Posted November 27, 2007 Maybe this: <?php echo '<a href="'.get_username ( $_SESSION['user_id'] ).'">http://runningprofiles.com/members/'.get_username ( $_SESSION['user_id'] ).'</a>'; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.