-1

I have a Minecraft server which I host for me and my friends which links to a site which shows ads to help pay for it. It redirects to a page on my site with parameters. The link it redirects with is:

http://swaba.gaming.multiplay.co.uk/adcookie.html?user=1603&gm=minecraft&clt_user=<MC-USERNAME>&srv_id=4332

I would like text on the site to say in a header:

Thank you <MC-USERNAME> for watching our advert!

The <MC-USERNAME> is the PHP variable clt_user passed through the redirect URL

My current code is

<h2>Thanks</h2>
<h2><?php echo htmlspecialchars($clt_user); ?></h2>
<h2>for watching our advert!</h2>    

How could I do this through PHP or PHP embedded in HTML. I have extremely basic knowledge of the language, so an explanation (through comments or text in the answer) would be nice but not necessary.

Thank you! EDIT: Just so you know, my site is no longer up so any urls in this question will probably link to a 404 page.

  • Question is David, do you already have `$_GET` arrays that already populate? I don't quite know what to make of it yet or if anything is working (or not) with your present URL. – Funk Forty Niner Jan 17 '16 at 19:39
  • I have `` in my html code –  Jan 17 '16 at 19:44
  • In other words, that's all you have and you're only hardcoding those values in your URL, correct? but need to tack on the other value? – Funk Forty Niner Jan 17 '16 at 19:46
  • I posted something for you below http://stackoverflow.com/a/34842899/1415724 – Funk Forty Niner Jan 17 '16 at 19:52
  • I have made an edit to my answer and that is why it's not working for you. You're using an `.html` extension and we don't know if you instructed Apache to treat `.html` files as PHP. Reload my answer about that. – Funk Forty Niner Jan 17 '16 at 20:02
  • Ok so does nginx parse PHP directives from `.html` file extensions? I have/had no idea under which platform you are running, you just dropped code on us and wondering why it's not working. I spent some time putting something together in thinking that your code doesn't work because of that. See my answer or see the other people's answers; I've done my best to provide you with a solution. Good luck, I sincerely with you well on this. – Funk Forty Niner Jan 17 '16 at 20:29

3 Answers3

0

You can try like this to get url param clt_user value using $_GET and then use it on your embedded html with php.

<?php
// to catch  clt_user value
$clt_user= $_GET['clt_user']; 
 ?>
<h2>Thanks</h2>
<h2 value="<?php 
echo htmlspecialchars($clt_user); ?>"></h2>
<h2>for watching our advert!</h2>    
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
  • 1
    I don't think the `

    ` tag supports the `value` param. I used it as an example as I know the `` tag supports it.

    –  Jan 17 '16 at 19:18
  • ^ you're right https://www.w3.org/TR/html-markup/global-attributes.html it doesn't @DavidWheatley so you should remove that from your question's code if you know it's not supported, because it's kind of deceiving/misleading. – Funk Forty Niner Jan 17 '16 at 19:30
0

Why not just:

<h2>Thanks <?php
               $clt_user = $_GET['clt_user'];
               echo htmlspecialchars($clt_user);
           ?> for watching our advert!</h2>

or better:

<h2>Thanks <?php echo htmlspecialchars($_GET['clt_user']); ?> for watching our advert!</h2>

even better (checking to see if has variable before printing):

<?php if($_GET['clt_user']){
    $clt_user = htmlspecialchars($_GET['clt_user']);
    echo '<h2>Thanks '.$clt_user.' for watching our advert!</h2>';
?>

Don't put it in a value attribute. Simply echo from the inside of the h2 tag. Also, the ouput you mentioned was on 1 line, so I combined them all into a single h2 element.

josh.thomson
  • 905
  • 9
  • 25
0

Seeing that you seem to only be coding in hard values in your URL, you can add PHP tags to the url with a GET array.

Here is an example:

<?php 
$_GET['clt_user'] = "john";
$clt_user = $_GET['clt_user'];
?>

<a href="http://swaba.gaming.multiplay.co.uk/adcookie.html?user=1603&gm=minecraft&clt_user=<?php echo htmlspecialchars($clt_user); ?>&srv_id=4332">Link</a>

<h2>Thanks</h2>
<h2><?php echo htmlspecialchars($clt_user); ?></h2>
<h2>for watching our advert!</h2> 

HTML source:

<a href="http://swaba.gaming.multiplay.co.uk/adcookie.html?user=1603&gm=minecraft&clt_user=john&srv_id=4332">Link</a>

<h2>Thanks</h2>
<h2>john</h2>
<h2>for watching our advert!</h2> 

However, you don't need (or may not need) all those extra tags. You can use it all in one line if desired.

<h2>Thanks
<?php echo htmlspecialchars($clt_user); ?> for watching our advert!
</h2> 

Edit:

There is something I have noticed though, you are using adcookie.html with .html as your file's extension. You would need to use a .php extension or instruct Apache your system to treat .html files as PHP if it isn't supported.

  • .html files by default, will not parse PHP directives.

That is why it's not working for you now, as you stated in comments.

Consult the following if you want to continue using .html as your preferred file extension.

So your URL link's page will contain something to the effect of, and using a .php file extension:

<?php 
$_GET['clt_user'] = "john"; // this will depend on where that is being fetched from
                            // this is only an example
$clt_user = $_GET['clt_user'];
?>

<a href="http://swaba.gaming.multiplay.co.uk/adcookie.php?user=1603&gm=minecraft&clt_user=<?php echo htmlspecialchars($clt_user); ?>&srv_id=4332">Link</a>

Then your adcookie.php file will contain:

<?php 
$clt_user = $_GET['clt_user'];
?>

<!DOCTYPE html>
<head></head>
<title></title>
    <body>
        <h2>Thanks
        <?php echo htmlspecialchars($clt_user); ?> for watching our advert!
        </h2>
    </body>
</html>
Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141