1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to display title in url in next page it loads.

Discussion in 'PHP' started by farooqwani, Jul 13, 2015.

  1. #1
    Hi,

    I want the title "Great Man" in the below url to display in the middle of the redirect page :
    URL :
    http://www.mydoamain.com/redirect.php?q=Great Man
    Code (markup):
    But cannot get it to display anywhere. Not even in the title tag.

    Help will be appreciated.

    Thanks.
     
    Solved! View solution.
    farooqwani, Jul 13, 2015 IP
  2. #2
    use

    <?php
    
    $q=$_GET['q'];
    
    ?>
    <title><?php echo $q; ?></title>
    Code (markup):
     
    KangBroke, Jul 13, 2015 IP
  3. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #3
    <?php echo $q; ?>
    PHP:
    And to display it anywhere on the page just use
     
    KangBroke, Jul 13, 2015 IP
  4. farooqwani

    farooqwani Well-Known Member

    Messages:
    266
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    158
    #4
    Thank you, worked :)
     
    farooqwani, Jul 13, 2015 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #5
    Some advice on that... use htmlspecialchars on that output:

    <?php echo htmlspecialchars($_GET['q']) ?>

    Otherwise people could pass javascript or other code in your $_GET data to make cross site scripting exploits. Remember, ALL user input is suspect and should be sanitized -- be it for passing to a database or sent back to the browser in the result.

    I'd probably also skip the "variable for nothing" if you are only using it once. If you are going to use it more than once, THEN put it into a variable.

    As Uncle Red often said, "You guys know me... Safety forced!"
     
    deathshadow, Jul 13, 2015 IP
    NetStar likes this.
  6. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #6

    Very good points to note, but all the OP asked was how to pull from the URL, and than said he just was trying to echo it to make sure it worked, I assumed that he would not use malicious code on his own platform.

    However I do agree we should go ahead and tell them everything if were going to bother telling them anything.
     
    KangBroke, Jul 13, 2015 IP
  7. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #7
    I assumed he wouldn't have the slightest idea how to write secure code since he asked such an elementary question.
     
    NetStar, Jul 13, 2015 IP
    KangBroke and deathshadow like this.
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #8
    That's my take on it too -- the question shows someone starting out and a bit green around the gills, to even MENTION blindly dumping out the value with echo... from $_GET? Herpafreakingderp in my book.

    Of course, if you only care about NEW php and have kicked 5.3/earlier to the curb, we don't need to say echo since the <?= shorttag now ALWAYS exists.

    <?= htmlspecialchars($_GET['q']) ?>
    Code (markup):
    Should work in 5.4/newer regardless of the shorttags setting.
     
    deathshadow, Jul 13, 2015 IP
    KangBroke likes this.