+ Reply to Thread
Results 1 to 9 of 9

Thread: Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

  1. #1
    chriscrowe43 is offline x10Hosting Member chriscrowe43 is an unknown quantity at this point
    Join Date
    Aug 2011
    Posts
    21

    Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

    Hello I was wondering if there is anyone that could help me figure out this problem im having. I have been racking my brain for two days trying to figure this out.


    Notice: Undefined offset: 1 in (site Root)/scripts/checkuserlog.php on line 76

    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in (site Root)/scripts/checkuserlog.php on line 80
    Something appears wrong with your stored log in credentials. Log in again here please

    Here's the code im dealing with.
    lines 72-95

    } else if (isset($_COOKIE['idCookie'])) {// If id cookie is set, but no session ID is set yet, we set it below and update stuff

    $decryptedID = base64_decode($_COOKIE['idCookie']);
    $id_array = explode("nm2c0c4y3dn3727553", $decryptedID);
    $userID = $id_array[1];
    $userPass = $_COOKIE['passCookie'];
    // Get their user first name to set into session var
    $sql_uname = mysql_query("SELECT username FROM myMembers WHERE id='$userID' AND password='$userPass' LIMIT 1");
    $numRows = mysql_num_rows($sql_uname);
    if ($numRows == 0) {
    echo 'Something appears wrong with your stored log in credentials. <a href="login.php">Log in again here please</a>';
    exit();
    }
    while($row = mysql_fetch_array($sql_uname)){
    $username = $row["username"];
    }
    $_SESSION['id'] = $userID; // now add the value we need to the session variable
    $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$userID");
    $_SESSION['username'] = $username;
    $logOptions_id = $userID;
    $logOptions_uname = $username;
    $logOptions_uname = substr('' . $logOptions_uname . '', 0, 15);

    im new to php and im totally at a loss. I want to impress that i dont want someone to do my work for me, i just really need to move beyond this. I have used previous versions of the (social website system) that i am currently working with and had no problems but this is a newer version with added coded and features that i need for my site. Please Help. And Thankyou so much ahead of time if you do!!
    also if there is anything i might need to add to help me get replies please let me know, i see that my post is getting views but im afraid i need to add something to get a reply that i havnt.
    Last edited by chriscrowe43; 09-24-2011 at 11:50 AM.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

    $userID = $userID = $id_array[1]; ;

    The error message is saying that there is nothing in $id_array[1];

    Hence, explode("nm2c0c4y3dn3727553", $decryptedID) on the previous line only returns one item.

    Add

    echo "\n<br />" ;
    echo $decryptedID;
    echo "\n<br />" ;

    before the 'explode' line to see what the problem is.
    Nothing is always absolutely so.

  3. #3
    chriscrowe43 is offline x10Hosting Member chriscrowe43 is an unknown quantity at this point
    Join Date
    Aug 2011
    Posts
    21

    Re: Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

    ok thank you ill check it out and update here

    ---------- Post added at 05:13 PM ---------- Previous post was at 05:04 PM ----------

    Ok i stuck the code in and tested it. and got nothing but updated line numbers showing that the code had been moved down.
    When you say that its telling that there is nothing in id array 1 im not sure what to thing about that as far as the database goes everything appears correct? unless i just dont understand what it means by nothing being there.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

    If
    echo $decryptedID;

    didn't produce anything, then

    base64_decode($_COOKIE['idCookie'])

    is returning either an empty string or FALSE.
    Nothing is always absolutely so.

  5. #5
    chriscrowe43 is offline x10Hosting Member chriscrowe43 is an unknown quantity at this point
    Join Date
    Aug 2011
    Posts
    21

    Re: Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

    what does that mean exactly ?

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

    It means $_COOKIE['idCookie'] probably is not in the proper format. Try printing it out and see what the value is.
    Nothing is always absolutely so.

  7. #7
    chriscrowe43 is offline x10Hosting Member chriscrowe43 is an unknown quantity at this point
    Join Date
    Aug 2011
    Posts
    21

    Re: Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

    im sorry i feel stupid but what do i need to do? how would i go about printing out what i need to print?
    Last edited by chriscrowe43; 09-24-2011 at 01:16 PM.

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

    Please use [php], [html] or [code] tags (as appropriate) to separate and format code.

    var_dump would provide a little more information about the variable contents, such as the type, and make it more obvious whether or not the variable held an empty string.

    empty would be a better test than isset, since a variable can be set but empty. For example:
    PHP Code:
    $foo '';
    isset(
    $foo) && empty($foo); # True. 
    Quote Originally Posted by chriscrowe43 View Post
    When you say that its telling that there is nothing in id array 1 im not sure what to thing about that as far as the database goes everything appears correct? unless i just dont understand what it means by nothing being there.
    Just what he says. Consider:

    PHP Code:
    $data 'abc';
    $parts explode('/'$data); 
    $parts has exactly one item (at index 0). There are no items at indices 1 or above because '/' doesn't appear in $data. Similarly, "nm2c0c4y3dn3727553" must not be appearing in $decryptedID, so $id_array has exactly 1 item (since a negative limit isn't passed to explode).

    Quote Originally Posted by chriscrowe43 View Post
    PHP Code:
        $decryptedID base64_decode($_COOKIE['idCookie']); 
    Base64 is an encoding. It provides no encryption. A less misleading name for the variable would be $decodedID. If you think this is a minor point, consider that the name is an assertion that the data is protected somehow by encryption, which provides a false sense of security that can result in an unsafe security protocol. Basically, when your users' accounts get hacked, it won't seem so insignificant.

    Quote Originally Posted by chriscrowe43 View Post
    PHP Code:
        $userID $id_array[1]; 
        
    $userPass $_COOKIE['passCookie'];
    // Get their user first name to set into session var
        
    $sql_uname mysql_query("SELECT username FROM myMembers WHERE id='$userID' AND password='$userPass' LIMIT 1"); 
    The sample code is vulnerable to SQL injection, which is a very serious security risk. Both the user ID and password are submitted by the user, so either can be used as an injection vector. To fix this hole, switch from the outdated mysql extension to PDO and use prepared statements. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO". The site you save may just be your own.

    Quote Originally Posted by chriscrowe43 View Post
    PHP Code:
        if ($numRows == 0) {
            echo 
    'Something appears wrong with your stored log in credentials. <a href="login.php">Log in again here please</a>';
            exit();
        } 
    Don't use die or exit when outputting HTML. You'll get invalid HTML.


    Quote Originally Posted by chriscrowe43 View Post
    PHP Code:
        while($row mysql_fetch_array($sql_uname)){ 
    Since you fetch at most 1 record, and have previously checked that the result has a row, the while is completely unnecessary. Simply:
    PHP Code:
        $row $result->fetch();
        
    $username $row["username"]; 
    Note: this example uses PDO rather than the mysql extension.

    Quote Originally Posted by chriscrowe43 View Post
    PHP Code:
        $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$userID"); 
    What's the purpose of this value?
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  9. #9
    chriscrowe43 is offline x10Hosting Member chriscrowe43 is an unknown quantity at this point
    Join Date
    Aug 2011
    Posts
    21

    Re: Undefined offset: 1 in (site root) /scripts/checkuserlog.php on line 76

    I'm sorry mission but your going way over my head. Mabey i have no business messing with this stuff but i really kind of need it, I know it is a probably a pain to deal with someone so uninformed about how php works but once i get passed this issue everything else normally seems to work or has worked with earlier versions of the system im trying to use. I just need someone that will help me work through this one thing one step at a time until i've resolved it. I appreciate your time spent in createing the reply but im lost. please bare in mind i have no offical education concerning all this and im learning as i go. thanks you again though.

    ---------- Post added at 06:57 PM ---------- Previous post was at 06:32 PM ----------

    Good News I figured out my problem yet again! lol, thanks for you help and i would still like to understand more about the security issues you mentioned earlier mission.
    Last edited by chriscrowe43; 09-24-2011 at 01:33 PM.

+ Reply to Thread

Similar Threads

  1. my web site is not on line
    By ploja in forum Free Hosting
    Replies: 1
    Last Post: 07-03-2010, 04:49 PM
  2. site is not on-line
    By altiva in forum Free Hosting
    Replies: 1
    Last Post: 01-30-2010, 10:02 AM
  3. Web site taken off line
    By sporkalot in forum Free Hosting
    Replies: 1
    Last Post: 11-05-2009, 01:50 PM
  4. Cannot use string offset as an array in...
    By darylcarpo in forum Programming Help
    Replies: 2
    Last Post: 10-28-2008, 11:03 AM
  5. Replies: 1
    Last Post: 11-09-2007, 05:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers