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
2
  • 3
    Even if you get this working, This should NOT be used to manage user sessions. Seriously. Commented Sep 25, 2013 at 13:26
  • Side note: only one RewriteRule is needed: RewriteRule ^([A-Za-z0-9_-]+)/?$ profile.php?user=$1 [L] Commented Sep 25, 2013 at 13:27

4 Answers 4

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");
Sign up to request clarification or add additional context in comments.

Comments

1
<?php echo $_GET['user']; ?>

2 Comments

Don't trust user data!
Of course not. This was just to demonstrate how to get that variable.
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.

Comments

0

filter the data you get from the url

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

echo $user;
?>

1 Comment

You forgot the $ at echo user ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.