Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: classes help

  1. #1
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default classes help

    Hello i am trying to do this thing but it just dose not want to work

    Code:
    <?php
    
    Class test
    {
    function call_function($value)
        {
    $value = mysql_query("SELECT * FROM users WHERE `username` = '$_SESSION[username]' AND `id` = '$_SESSION[id]' AND `password` = '$_SESSION[password]'");
       $value = mysql_fetch_array($value);
       return $value;
        }
    function call_function2($value)
        {
     $value = mysql_query("SELECT * FROM profile WHERE `username` = '$_SESSION[username]'");
       $value = mysql_fetch_array($value);
       return $value;
        }
    }
     
    $script = new test();
    
    echo("$script->call_function(username)");
    
    ?>
    But it dose not show the user name ??? when i echo $script->call_function(username)

  2. #2
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    PHP Code:
    <?php

    class test
    {
    function 
    call_function()
        {
    $value mysql_query("SELECT * FROM users WHERE `username` = '$_SESSION[username]' AND `id` = '$_SESSION[id]' AND `password` = '$_SESSION[password]'");
       
    $value mysql_fetch_array($value);
       return 
    $value;
        }
    function 
    call_function2($value)
        {
     
    $value mysql_query("SELECT * FROM profile WHERE `username` = '$_SESSION[username]'");
       
    $value mysql_fetch_array($value);
       return 
    $value;
        }
    }
     
    $script = new test;

    $var $script->call_function();
    echo 
    $var;

    ?>

  3. #3
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default

    how would that work if your not telling the call_function if to show the username or what ever out of the database.

  4. #4
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    because if $_SESSION[username] is set, you don't need to define it in the function, its in the session.

  5. #5
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default

    yes but if you look its only SELECT * FROM ...

    how will it know to show the username from the table or the userlevel or what ever i want to it show?

  6. #6
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Change 'return $value;' to 'return $value["username"];' or something then.

  7. #7
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default

    Okay i am trying this anther way

    but i keep getting this error
    Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';'

    and this is the code

    Code:
    $user = mysql_query("SELECT * FROM users WHERE `username` = '$_SESSION[username]' AND `id` = '$_SESSION[id]' AND `password` = '$_SESSION[password]'");
       $user = mysql_fetch_array($user);
      Class abc
    {
    var $u;
    $this->u = $user[username];
    }
    $script = new abc;

  8. #8
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    PHP Code:
    <?php

    $query 
    "SELECT * FROM users WHERE `username` = '$_SESSION[username]' AND `id` = '$_SESSION[id]' AND `password` = 

    '
    $_SESSION[password]'";

    $user mysql_query$query );

    $fetch mysql_fetch_array$user );

    class 
    abc
    {

    var 
    $u;

    }

    $script = new abc;
    $script->$user[username];

    ?>
    You really need to sort out the way you code, it's horrible.

  9. #9
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    Its worse then mine... plus, why are you storing a password, in a session.. is it plaintext or encoded? Very bad security risk.

  10. #10
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    As long as its hashed its not a security risk. The only way you can access a session is via PHP or the server and if one of them is compromised then I think you have more to worry about than a hashed password stored in a session.

    Quote Originally Posted by Dentafrice, View Post
    Its worse then mine... plus, why are you storing a password, in a session.. is it plaintext or encoded? Very bad security risk.

Page 1 of 2 12 LastLast

Posting Permissions

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