0

I've made it so when you click on a certain link it changes the url to mywebsite.com/page.php#certainusername

How can I make it so when the url contains someone's certain username, an object containing

data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=certainusername" 

will change certain username to the username in #?

quietess
  • 11
  • 1

3 Answers3

0

Check out the parse_url function. You should be able to get the fragment (hashmark thing) from that.

reallyxloco
  • 114
  • 2
0

Not sure what kind of change you are talking about... So here are 3 different types of methods to access the "#certainusername"

CSS

:target {
   background: yellow;
}

(Source)


PHP

parse_url($url, PHP_URL_FRAGMENT)
// or
parse_url($url)['fragment']
// then do stuff ...

(Source)


JavaScript

window.location.hash

(Source)

Community
  • 1
  • 1
HandyDan
  • 425
  • 2
  • 8
0

For the question, I assume that you're not working with any framework. Given this, I'll give you a simple answer.

Steps:

1 - Get the username out of the URL.

2 - Generate the view dynamically.

Explanation:

1 - I would recommend using a query string of the following format: mywebsite.com/page.php?username=certainusername (instead of using a #) Then you can use $_GET to obtain the username (Please, read more about the security implications: http://php.net/manual/en/reserved.variables.get.php).

2 - If you're using PHP to generate the HTML code directly, the only thing that you need to do is:

... HTML in here ...
data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=<?php echo $username; ?>"
... more HTML ...

(Assuming that the variable $username contains the username obtained from the URL).

This is a very simple scenario and there are a lot of other things to consider that are out of the scope of the question.

federicojasson
  • 362
  • 4
  • 14