Results 1 to 8 of 8
  1. #1

    Wrong datatype for second argument for in_array()

    Hello,

    I wrote a little function;

    PHP Code:
    <?php session_start(); ob_start();
    $salladim $_SESSION['salla'];
    $salladin =  isset($_GET['url'])?$_GET['url']:'' ;
     
    if(!
    in_array($salladin,$salladim))
    {
        
    header'refresh: 1; url='.$_SERVER['HTTP_REFERER'].'' );
    echo 
    '<h2>Hazirlaniyor...</h2>';
        exit();
    }
    When i run this code, i get the following error :
    PHP Code:
    PHP Warning:  in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argument in /home/site/public_html/do.php on line 5 

  2. #2
    Join Date
    Jan 2010
    Location
    MT
    Posts
    45
    What do you get if you do:
    PHP Code:
    var_dump($_SESSION['salla']); 
    It looks like your session variable is not an array, which it needs to be for the second argument in in_array().
    Shout! Radio Services
    Developer of Shout! Radio Automation
    Complete cloud-based radio station automation.

  3. #3
    PHP Code:
    var_dump($_SESSION['salla']); 
    not working

  4. #4
    how to fix this error

  5. #5
    Join Date
    Mar 2009
    Posts
    3,807
    do you even have a "salla" in your session?

  6. #6
    Quote Originally Posted by quantumphysics View Post
    do you even have a "salla" in your session?
    this script

    PHP Code:
    <?php session_start();
    function 
    kodsalla($uzunluk
    {
    $karakterler "0123456789"."ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $kod "";
      while(
    strlen($kod) < $uzunluk
      {
        
    $kod .= substr($karakterler, (rand() % strlen($karakterler)), 1);
      }
      return(
    $kod);
    }
    $kodsalla kodsalla(8);

    $_SESSION['salla'][] = $kodsalla;

  7. #7
    how to fix this error pls help me thanks

    PHP Code:
    var_dump($_SESSION['salla']); 
    PHP Code:
    array(1) {
      [
    0]=>
      
    string(8"4AZWX25C"

    Last edited by codetr; 05-30-2011 at 12:21 PM.

  8. #8
    Join Date
    May 2004
    Location
    NYC
    Posts
    793
    Your code actually runs fine for me and does not generate any errors.

    All I can think is...try putting session_start() after ob_start().

    PHP output buffering and session handling is sometimes configured in such a way that it requires ob_start() to come before session_start(). In other cases, the order doesn't matter.

Similar Threads

  1. [PHP] Wrong datatype for second argument
    By latheesan in forum Programming Discussion
    Replies: 3
    Last Post: 04-08-2008, 01:29 PM
  2. Wrong datatype for second argument for in_array()
    By latheesan in forum Programming Discussion
    Replies: 9
    Last Post: 02-16-2008, 12:16 PM
  3. MySQL Datatype Question
    By Ricjustsaid in forum Programming Discussion
    Replies: 6
    Last Post: 12-05-2007, 02:31 AM
  4. in_array module.
    By horizon in forum Programming Discussion
    Replies: 1
    Last Post: 07-16-2006, 02:59 PM
  5. Do you store time as UNIX TIMESTAMP or MySQL time datatype?
    By [email protected] in forum Programming Discussion
    Replies: 3
    Last Post: 03-01-2005, 06:07 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
  •