SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question $_self not working w/a dynamic page.

    PHP Code:
    <?php echo htmlentities ($_SERVER['$_SELF.PHP']);  ?>" method="POST">
    From what i have read up self will automatically take the user to the index page, which is what is happening to me. Rather than showing the results on the "guestbook.inc.php file wich the code is on.
    I tried
    PHP Code:
    <?php echo htmlentities ($_SERVER['pages/guestbook.inc.php']);  ?>" method="POST">
    (subbing the directory & file name)
    but got a 403 error.
    still searching for how to fix this. Anyone here has any suggestions or could point me to a good clear link?
    Was looking at stack overflow but this guy's answer had six or more line of codes and a new function to redirect the link. Thougth there would be a simpler solution?

  2. #2
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    You're looking for $_SERVER['PHP_SELF']

    See also PHP $_SERVER superglobal documentation

  3. #3
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hey go Team Fortress (I play the scout, the heavy, doctor and sniper somtime. I die a lot in it...)
    yes the 'PHP_SELF' was actually a typo on my part sorry.
    My problem is that it work fine on its own page (guestbook.php). but when it is in page that is dynamic(guestbook.inc.php) that is called by index php. it doesn't work. it takes me back to index php.
    I need to find out how to make it post to the page it is on.

  4. #4
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    Perhaps the __FILE__ constant, which points to the path of the currently executing file?

  5. #5
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I am actually quite new at php.
    would I place the _FILE_ constat, & i'll google that...in the place of 'pages/guestbook.inc.php' ?
    <?php echo htmlentities ($_SERVER['pages/guestbook.inc.php']); ?>

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    That FILE is surrounded by TWO underscores __FILE__ and other PHP predefined constants.

    Create a page with this in it and look carefully at the output.
    server.php
    PHP Code:
    <?php

    echo 'These are your SERVER variables available from every script <hr />';
    var_dump($_SERVER);

    ?>

  7. #7
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hello Cups and thank you for your reply...but it did absolutely nothing.

  8. #8
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    996
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    You can also use <form method="post"> (html5) or <form action="" method="post"> (html4) to make a form post to the current document's URI.

  9. #9
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thank you Tom, but I am trying to learn php.

  10. #10
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    am I heading in the right way w/this?
    <form action="<?php pages(__FILE__).'/guestbook.inc.php'; ?>" method="POST">

  11. #11
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by pdxSherpa View Post
    Hello Cups and thank you for your reply...but it did absolutely nothing.
    Did you save a file called server.php containing the code I showed you?

    Put server.php in your document root then fire up this address:

    http://localhost/server.php

    or

    http://127.0.0.1/server.php

  12. #12
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hello cups. Sorry I had not correctly understood you.
    I tried again. created the file named it server.php same directory as the index file (not part of the dynamic pages) added the code
    <?php

    echo 'These are your SERVER variables available from every script <hr />';
    var_dump($_SERVER);

    ?>
    when I run I get the "These are your SERVER variables available from every script" & a whole lot of of other info...like ""C:/xampp/htdocs" ["REQUEST_SCHEME"]=> string(4) "http" ["CONTEXT_PREFIX"]=> string(0) "" ["CONTEXT_DOCUMENT_ROOT"]=> string(15) "C:/xampp/htdocs" ["SERVER_ADMIN"]=> string(20) "postmaster@localhost" ["SCRIPT_FILENAME"]=> string(40) "C:/xampp/htdocs/phpjSRevw/php/server.php" ["REMOTE_PORT"]=> string(5) "61745" ["GATEWAY_INTERFACE"]=> string(7) "CGI/1.1" ["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1" ["REQUEST_METHOD"]=> string(3) "GET" ["QUERY_STRING"]=> string(0) "" ["REQUEST_URI"]=> string(25) "/phpjSRevw/php/server.php" ["SCRIPT_NAME"]=> string(25) "/phpjSRevw/php/server.php" ["PHP_SELF"]=> stri"

    i have no idea what to do with it.
    D

  13. #13
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    $_SERVER is a built in array in PHP (http://php.net/manual/en/language.types.array.php). You can call one of these variables at any time. Say I need to get the current file that I am in, I can do this:

    Code PHP:
    echo $_SERVER["SCRIPT_FILENAME"];

    You'll notice that the result is also located in the var_dump that you did.

    A little pointer for the forums, please try to use the proper code highlighting when pasting stuff in here, makes things a lot easier on those who are trying to answer your question.

  14. #14
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ok. will try it tomorrow,thank you much and promise to be more conscientious about using proper code tagging in the future!
    d

    Quote Originally Posted by K. Wolfe View Post
    $_SERVER is a built in array in PHP (http://php.net/manual/en/language.types.array.php). You can call one of these variables at any time. Say I need to get the current file that I am in, I can do this:

    Code PHP:
    echo $_SERVER["SCRIPT_FILENAME"];

    You'll notice that the result is also located in the var_dump that you did.

    A little pointer for the forums, please try to use the proper code highlighting when pasting stuff in here, makes things a lot easier on those who are trying to answer your question.

  15. #15
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Go back to your original post and you will see you were trying to access a SERVER variable that did not exist.

    PHP Code:
    <?php echo htmlentities ($_SERVER['$_SELF.PHP']);  ?>" method="POST">
    This showed that you did not know what you were doing.

    The dump of SERVER variables you made now shows you all of the variables you can pick from, you can read them, echo them out onto the screen or use them to make strings for links etc.

    You can do that var_dump($_SERVER) on any page you are developing on when you want to check which variables apply to that particular page.

    Its really useful, its only one line, and you can comment it out or remove it before you publish the webpage -- in fact you MUST -- it contains lots of information that would be of interest to a potential cracker.

    So now to return to the points made earlier in this thread you can edit that server.php page slightly and then compare the output of the following:

    server.php
    PHP Code:
    <?php
    // comment out that readout, maybe uncomment it later ... else remove these lines
    //echo 'These are your SERVER variables available from every script <hr />';
    //var_dump($_SERVER);

    echo "The host for this site is " $_SERVER['HOST'] . '<hr />';
    echo 
    "This exact script is " $_SERVER['SCRIPT_FILENAME'] . '<hr />';
    echo 
    "The __FILE__ variable for this exact script is " __FILE__ '<hr />';

    // now create some conditional messages depending on one of those variables ...

    if($_SERVER['SCRIPT_FILENAME'] === "server.php"){

    echo 
    'You have found the server vars page';

    }else{

    echo 
    'This is not the server vars page';
    }


    ?>

  16. #16
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, I already knew I didn't know what I was doing. If I did I wouldn't have asked for help on a forum.
    But will try this out. thanks.
    As for the server variable that doesn't exist...Again. I have the file it is there.
    it work on its own. but not when called in a dynamic page settings.
    The rather than posting text to itself it takes me back to the index file.

    Quote Originally Posted by Cups View Post
    Go back to your original post and you will see you were trying to access a SERVER variable that did not exist.



    This showed that you did not know what you were doing.

    The dump of SERVER variables you made now shows you all of the variables you can pick from, you can read them, echo them out onto the screen or use them to make strings for links etc.

    You can do that var_dump($_SERVER) on any page you are developing on when you want to check which variables apply to that particular page.

    Its really useful, its only one line, and you can comment it out or remove it before you publish the webpage -- in fact you MUST -- it contains lots of information that would be of interest to a potential cracker.

    So now to return to the points made earlier in this thread you can edit that server.php page slightly and then compare the output of the following:

    server.php
    PHP Code:
    <?php
    // comment out that readout, maybe uncomment it later ... else remove these lines
    //echo 'These are your SERVER variables available from every script <hr />';
    //var_dump($_SERVER);

    echo "The host for this site is " $_SERVER['HOST'] . '<hr />';
    echo 
    "This exact script is " $_SERVER['SCRIPT_FILENAME'] . '<hr />';
    echo 
    "The __FILE__ variable for this exact script is " __FILE__ '<hr />';

    // now create some conditional messages depending on one of those variables ...

    if($_SERVER['SCRIPT_FILENAME'] === "server.php"){

    echo 
    'You have found the server vars page';

    }else{

    echo 
    'This is not the server vars page';
    }


    ?>


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •