0

I just wanted to know if i can display my logged in username such as http://website.com/username /username would be the username and to display the username on profile.php how can i display that in a echo? or variable here is my ht accesses below if needed

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1

4 Answers4

2
<?php
if(isset($_GET['user'])) {
    echo $_GET['user'];
}
?>

or short version:

// Use outside php tags
<?=(isset($_GET['user']) ? $_GET['user'] : "guest")?>

// use inside php tags
echo (isset($_GET['user']) ? $_GET['user'] : "guest");
Joran Den Houting
  • 3,149
  • 3
  • 21
  • 51
1
<?php echo $_GET['user']; ?>
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

filter the data you get from the url

<?php 
$user = filter_var($_GET['user'], FILTER_SANITIZE_STRING);

echo $user;
?>
Prix
  • 19,417
  • 15
  • 73
  • 132
timod
  • 585
  • 3
  • 13
0

anything that is in the url with this type: page.php?var1=x&var2=2 can be accessed via the global $_GET array because it's a variable sent by get protocol.

so the var1 and var2 in my example can be found in $_GET['var1'], $_GET['var2']. and in your case if the page is website.com/profile.php?username=SomeUser you can use $_GET['username'].

One last thing, NEVER under any circumstances, use the user input accessed through the global arrays directly in your code, evaluate it, clean it, escape it, what ever you need , then use it.

Labib Ismaiel
  • 1,240
  • 2
  • 11
  • 21