Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

php and query string

  • 09-04-2008 02:40PM
    #1
    Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭


    hey guys, totally new to php but coming from perl.

    i have a logout.php that basically unsets all $_SESSION variables that i've set and redirects to an index.php with a query string like so index.php?message=logged out successfully.

    now back in the index.php page i'd like to display a message to the user saying that they have just logged out.

    since i'm coming from perl i'm mad into regular expressions and could easily do a regex on $_SERVER but i fear there may be a much more easier way of getting the message variable from the query string. $_GET doesn't work as it hasn't been sent by a html form i presume.

    i know php is great for these global arrays eg $_SERVER and $_SESSION but is there one that holds all the variables from the query string?


Comments

  • Registered Users, Registered Users 2 Posts: 6,652 ✭✭✭daymobrew


    Cremo wrote:
    $_GET doesn't work as it hasn't been sent by a html form i presume.
    It will work for the example url you provided. Maybe use 'index.php?message=loggedout' and then your index.php will have something like:
    [PHP]if ( defined( $_GET == 'loggedout' ) ) {
    echo '<p>You have been logged out.</p>';
    }[/PHP]


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Google for the php $_POST and $_GET variables and all shall be revealed.


  • Closed Accounts Posts: 8,478 ✭✭✭GoneShootin


    Cremo wrote: »
    $_GET doesn't work as it hasn't been sent by a html form i presume.


    $_GET will work fine in this case as it doesn't require any submit to a form for it to be displayed at the target page. $_GET will check the URL and handle the paramaters after the "index.php?" appropriately.

    As $_GET and $_POST are arrays, to debug you can always use something like:

    print_r($_GET);

    This will print the contents of a $_GET array and help you debug...

    Show us your code and it will make it easier to sort it out.


  • Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭Creamy Goodness


    oops i made a bad noob mistake.

    i had the redirect as index.php?msg=loggedout and was using $_GET in the index.php.

    :pac:


  • Closed Accounts Posts: 8,478 ✭✭✭GoneShootin


    It happens to everyone :) I've wasted too much time on different occasions trying to troubleshoot what seemed a complicated problems only to find that it was something as trivial as an incorrectly spelled variable.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 6,652 ✭✭✭daymobrew


    only to find that it was something as trivial as an incorrectly spelled variable.
    The lack of variable declaration and verification is one of the things I feel is lacking in PHP. In perl 'use strict' and 'use warnings' go a long way to preventing such trivial errors.

    Is there anything similar in PHP?


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    daymobrew wrote: »
    Is there anything similar in PHP?
    Yep

    http://us3.php.net/error_reporting


  • Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭Creamy Goodness


    daymobrew wrote: »
    The lack of variable declaration and verification is one of the things I feel is lacking in PHP. In perl 'use strict' and 'use warnings' go a long way to preventing such trivial errors.

    Is there anything similar in PHP?

    aye strict and warnings have save me - no scratch that, my employer - many hours :D
    Webmonkey wrote: »


    cool handy to know.


Advertisement