php ?id=

danielneridanielneri WP V.I.P.VPS - Virtual Prince of the Server
ok so whats the function called when someone does

[PHP]index.php?id=something_here[/PHP]

or whats the code for defining the id tag
anyone?
ban1.gif

Comments

  • NuvoNuvo Forum Leader VPS - Virtual Prince of the Server
    I have no idea what you're asking...
    That's just a query string.
    Basically, all that does is go to index.php and take some variable values with it.
    Defining the value of a query string variable with php is as simple as:
    [php]
    $var = 1234;
    echo "<a href=\"index.php?variable=".$var.">LINK</a>");
    [/php]
    Once that's done, you can easily get the value of $var on the page linked to by using:
    [php]
    $var = $_GET;
    [/php]
    There's no function usage other than echo (or print, which ever takes your fancy) involved, just variable setting and printing.
    Of course, on the page you have linked to, you'll want to do something with the variable values sent, but that's up to you to figure out since I have no idea what you're coding, but it's usually a case of:
    [php]
    if($var == 1234){
    //do something here
    }elseif($var != 1234){
    //do something else
    }
    [/php]

    It's not reccomended that you use query strings for pages which will require that you send confidential data, for that you should use $_POST and firms with the method set to post as it won't show the contents in the address bar.
    URL rewriting is also a good thing to look at if you're using query strings as search engines don't like query strings and don't index many pages that use them.
    PHP, CSS, XHTML, Delphi, Ruby on Rails & more.
    Current project: CMS Object.
    Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
    Release date: NEVER!!!
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    ah thanks for your quick reply mate

    im trying to make a membership system by myself...

    i want to have one page to do all the login/logout/registering functions for me.

    so i just have login.php

    [PHP]<?php

    include 'connect/config.php';
    {
    session_start()

    $_GET["id"];


    //Login
    if($id == login){

    $username = $_POST["username"];
    $password = $_POST["password"];

    $login = "SELECT username,password FROM members WHERE username='$username AND password='$password'";
    $result = mysql_query($login);

    //user found, assign variables...
    if(!$result)
    {
    $_SESSION = mysql_result($result,0,"username");
    $_SESSION = mysql_result($result,0,"password");
    echo "Welcome back $username.";
    }

    }


    //logout
    if($id == logout){
    session_destroy()
    header("Location: index.php");
    }

    ?>


    [/PHP]


    help me out here please

    i want each function to have its own query string
    etc. index.php?id=login
    index.php?id=logout
    index.php?id=register


    any ideas?
    ban1.gif
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    right never mind i fixed it

    heres the code i have now for login.php

    [PHP]<?php

    include 'connect/config.php';
    {
    session_start();

    if($QUERY_STRING == "") {
    // Main Page
    echo "nothing here...";
    } elseif($QUERY_STRING == "login") {
    // log in the user
    $username = $_POST["username"];
    $password = $_POST["password"];

    $login = "SELECT username,password FROM members WHERE username='$username' AND password='$password'";
    $result = mysql_query($login) or die(mysql_error());

    //user found, assign variables...
    if(!$result)
    {
    echo "Welcome back $username.";
    }
    else
    echo "Invalid username/password, please try again.";

    }
    elseif($QUERY_STRING == "logout") {
    // logout the user
    session_destroy();
    header("Location: index.php");
    } else {
    // Page not found
    echo "Oops.. Page not found (404)";
    }

    }
    ?>
    [/PHP]


    i looked up php query string

    that helped alot!
    thanks nuvo


    i still have one question though, any idea how to put a cookie or session so the user will remain logged in, kind off a remember me feature??
    ban1.gif
  • FelixFelix Junior Member Shared Hoster
    Ok just a few things to help you. You should consider using switch() in the future instead of using lots of if, else conditional statements.
    [PHP]
    // Switch example
    $var = "1234";
    switch($var)
    {
    // Is var 2222?
    case "2222":
    // Execute code here if it is!
    // Is it equal to 3333?
    case "3333":
    echo "it is 3333!";
    /* Default is exact same as else, meaning if none of the above are true
    we execute the following chunk of code */
    case default:
    echo "foooooo";
    }
    [/PHP]

    Secondly if you want to set a cookie you simply use setcookie() function.
    [PHP]
    // Example of setting a cookie
    $foo = "blaaaaaaaaa";
    // Set a cookie called foo with the value of $foo and to last one hour
    setcookie("foo",$foo,time() + 3600)
    [/PHP]

    To check if a cookie exists use the global $_COOKIE array.
    [PHP]
    // Checks if cookie exists
    if(isset($_COOKIE))
    {
    // Some code here.....
    }
    [/PHP]

    You should only use cookies if you want a remember me feature, in other words users don't login everytime they visit your site.

    If you want to remember a user's login just temporarily i.e. until they close their browser, you should consider using sessions. Use the session_start() function to initialise session data and $_SESSION to set or get the value of a session variable.
    [PHP]
    // Initialise session data.
    session_start();

    // Set a session
    $_SESSION = "foo";
    [/PHP]

    The above example sets the username foo into the global $_SESSION array. $_SESSION variables can then be used on all other pages. This is a great way of remembering certain data for all your website's pages.

    Checking if a session exists is simple..
    [PHP]
    if(isset($_SESSION))
    {
    // FOOOOOOOOO
    }
    [/PHP]

    On earlier versions of PHP you need to register a session before it can be used with the session_register() function. Incase you are using any PHP versions before PHP4 you will need to know this!

    If you want to remove any session data simply use unset()
    [PHP]
    unset($_SESSION);
    [/PHP]

    To destroy a cookie you need to actually reset it but set the expiration date on it to an earlier point!
    [PHP]
    // destroy a cookie
    setcookie("foo",$foo,time() - 3600);
    [/PHP]

    Thats practically all. :)
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    amazing felix thanks alot

    only one more problem

    if i use the switch function, i cant get a query string ex. index.php?login
    ban1.gif
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    alright guys today if officially the best day of my life!!

    i did it!!

    i've finally created a fully functional membership, using sessions, all thanks to the extreme help from devdreams!!!

    thanks to Felix and Nuvo!!!!

    http://www.vipercreations.com/member





    p.s. pm if you find a bug please thanks
    ban1.gif
  • PythonPython Forum Leader The Royal RAM
    I just went there and there are no files...

    The Royal Ram

  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    yeah sry i moved it to the index, nvm im having problems integrating it into my index...
    ban1.gif
Sign In or Register to comment.