1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Adding predefined text to webpage

Discussion in 'PHP & Perl' started by mandude, Mar 2, 2012.

  1. mandude

    mandude Jr. VIP Jr. VIP Premium Member

    Joined:
    Feb 18, 2008
    Messages:
    797
    Likes Received:
    306
    Location:
    Tampa FL
    Not sure if that title encapsulates what I am trying to say, but basically I have the script that can work if the page is on the root of the domain with htaccess, but not in a subfolder.

    I just want an easy way to have it so if I type in a domain name such as: www.mysite.com/hi that it will put it in the page where I want.

    The code I had was something like:

    PHP:
    $item $_GET['item'];
    if (!
    $item$item "test";

    $item2 str_replace("-"" "$item);
    then in the page it would have
    PHP:
    <?=$item2;?>
    but I cant get it to work. help please!
     
  2. inviz

    inviz Newbie

    Joined:
    Jun 15, 2010
    Messages:
    45
    Likes Received:
    5
    So, If I understand you right, you have a file in your root folder you want to include in a subfolder?

    foo.php (in your document root, wich could be /www/ or /public_html/)
    PHP:
    <?php
    if(isset($_GET['item']) {
    $item $_GET['item']; }
      else {
    $item "test"
             }

    $item2 str_replace("-"" "$item); 
    ?>
    then in a subfolder called /hi/
    PHP:
    <?php
    require_once($_SERVER['DOCUMENT_ROOT'] . "foo.php");
              
                      echo 
    $item2;
    ?>
     
    Last edited: Mar 3, 2012
  3. mandude

    mandude Jr. VIP Jr. VIP Premium Member

    Joined:
    Feb 18, 2008
    Messages:
    797
    Likes Received:
    306
    Location:
    Tampa FL
    Well the thing is I don't want to use it on the root, because the root is a real website. But I want this function to work in a subfolder.
    I guessed I messed up what I was trying to say with the /hi example. What it really would be is www.site.com/subfolder/hi
    and then the page would reflect that with the word hi in the place of 'item'

    I can get it to work on the root, but not in a subfolder.
     
  4. BlueZero

    BlueZero Power Member

    Joined:
    Jul 6, 2011
    Messages:
    500
    Likes Received:
    257
    Occupation:
    Webdeveloper, Project Manager
    Location:
    Byte in the Net
    Home Page:
    If i would be able to understand what you mean, then i would help you.
    You are testing GET parameter item, but in your url is nothing like that.

    If you just want to use a script from your root, when the url directs to your subdomain, then the example that inviz provided is correct.
     
  5. mandude

    mandude Jr. VIP Jr. VIP Premium Member

    Joined:
    Feb 18, 2008
    Messages:
    797
    Likes Received:
    306
    Location:
    Tampa FL
    I figured it out, I used a .htaccess to get it to work. if anyone wants to know what i did i can post it, but my problem is solved!