cereal 1,524 Nearly a Senior Poster Featured Poster

So if $camp['pozitie'] has a specific value and $camp['cod_garantie'] is empty, you have to alter all the following positions, correct?

You can add a counter and add it to the position key, here's an example:

<?php

$datum[] = array('name' => 'sun', 'pos' => 1, 'magnitude' => '-26.74');
$datum[] = array('name' => 'venus', 'pos' => 2, 'magnitude' => '-5');
$datum[] = array('name' => 'sedna', 'pos' => 3, 'magnitude' => '');
$datum[] = array('name' => 'neptune', 'pos' => 4, 'magnitude' => '8');
$datum[] = array('name' => 'io', 'pos' => 5, 'magnitude' => '');
$datum[] = array('name' => 'moon', 'pos' => 6, 'magnitude' => '-12.74');

echo PHP_EOL;

$i = 0;

foreach($datum as $key => $value)
{
        if(empty($value['magnitude']))
        {
                $i++;
        }

        if($i > 0) $value['pos'] = $value['pos'] + $i;

        echo "\t" . $value['pos'] . ' ' . $value['name'] ."\t" . $value['magnitude'] . PHP_EOL;
}

echo PHP_EOL;

will output:

1 sun       -26.74
2 venus     -5
4 sedna 
5 neptune   8
7 io    
8 moon      -12.74

Note rows 4 and 7, the original values are 3 and 5.

cereal 1,524 Nearly a Senior Poster Featured Poster
cereal 1,524 Nearly a Senior Poster Featured Poster

I'm not sure if you're using a backtick at the end of the command to wrap \r\n, you have to use single quotes instead, so the correct command should be:

LOAD DATA LOCAL INFILE 'C:\\temp\\test.csv' INTO TABLE bd_george.test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\r\n' (id,name);

Bye.

cereal 1,524 Nearly a Senior Poster Featured Poster

Solved:

create procedure process_asset_update (in Cost_Of_Acquisition double, in Estimated_Useful_Life double, inout Monthly_Depreciation double, inout Estimated_Residual_Value double, inout Accumulated_Depreciation double, in Asset_ID integer)
BEGIN
    declare result double(10,2) default '0.00';
    select au.Accumulated_Depreciation into result from asset_update as au order by au.Asset_ID desc limit 1;
    set Monthly_Depreciation = (Cost_Of_Acquisition / Estimated_Useful_Life)/12;
    set Estimated_Residual_Value = 10 * (Cost_Of_Acquisition);
    if result is null then set Accumulated_Depreciation = Monthly_Depreciation;
    else set Accumulated_Depreciation = Monthly_Depreciation + result;
    end if;
END|

It was the order by statement of the select query, it was referring to Asset_ID variable of the procedure not to the field name of the table, just change it to au.Asset_ID. Now it outputs:

+----+------+------+-------+--------+
| ID | CoA  | EUL  | MD    | AD     |
+----+------+------+-------+--------+
|  1 | 2500 |    5 | 41.67 |  41.67 |
|  2 | 2000 |    4 | 41.67 |  83.33 |
|  3 | 3000 |    6 | 41.67 | 125.00 |
|  4 | 1500 |    3 | 41.67 | 166.67 |
|  5 | 5000 |    9 | 46.30 | 212.96 |
+----+------+------+-------+--------+
5 rows in set (0.00 sec)

Live example: http://sqlfiddle.com/#!2/af493/1/0
Full code is attached.

As reference, the issue in my previous code is due to a naming conflict:

In addition, since float and double numbers are not accurate you should switch to decimal, read this for more information:

Bye!

mmcdonald commented: Nice work! OP Should add rep too 100% imo, Michael +4
cereal 1,524 Nearly a Senior Poster Featured Poster

The problem is that the Yahoo API Terms of Use does not allow to store data for more then 24 hours, so, you can just cache for a day and then you have to request the data:

This means that you can still write data to Cassandra or to a memory cache as Memcached or Redis and use a cronjob to remove it after 24 hours. So: no collection, just cache.

If you're still in doubt regarding the permission to save data, then you may want to ask to the Yahoo Developer Forum:

Probably in the YQL forum or the General forum.

Regarding the script to save data from the links you posted above, you can refer to the example that I wrote to you in a previous thread:

If you've still problems then show your code.

cereal 1,524 Nearly a Senior Poster Featured Poster

Not sure what you asking for, provide your code. Anyway you could use mod_alias module in Apache:

That way you can return data from from server2 without actually seeing it, for example set this in server1 config file:

Alias /remotefiles http://server2.tld/files
<Location /remotefiles>
    Order allow,deny
    Deny from all
    Allow from 192.168.0.10
</Location>

Where the 192.168.0.10 is server1 IP. That way your scripts can access to those resources just by using:

$_SERVER['DOCUMENT_ROOT'] . "/remotefiles/some.doc"

You should put a similary rule in server2 to allow access only from server1:

<Directory /files>
    Order allow,deny
    Deny from all
    Allow from 192.168.0.10
</Directory>

If instead you want to enable public access then change the above rule to:

<Location /remotefiles>
    Order allow,deny
    Allow from all
</Location>

But I think this is the reverse of what you want. So explain better or provide some code. Bye.

cereal 1,524 Nearly a Senior Poster Featured Poster

Go to: https://github.com/laravel/laravel

Click on download in the right side of the page, unzip the file and move everything to the folder that will run the website. Use the installation notes to be sure to create a public_html directory, this is where you have to publish css and javascript files.

Another method consists into the installation of Composer:

And then run this command from the prompt of commands (cmd.exe):

composer create-project laravel/laravel --prefer-dist .

Where the dot is the path in which you want to install the framework.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, it seems related to permissions. You should check the user running Apache (usually www-data) and switch the ownership of the files and subdirectories of /var/www/code to it, run this:

ps -aux |grep apache2

to see the user, the parent is root, all the child processes should be owned by www-data or another defined user in /etc/apache2/apache2.conf, and then change the ownership:

sudo chown www-data:www-data -R /var/www/code

If this still does not work, then change the write permissions:

sudo chmod 755 -R /var/www/code

Note that 755 works if the owner of the files is the same user used by Apache, otherwise you need to use 777, which can be fine in a development box, but it is not good in a production server. Hope this helps to solve the problem.

iamthwee commented: Excellent +14
cereal 1,524 Nearly a Senior Poster Featured Poster

If you still have problems it may be related to this query:

$query_result1 = Yii::app()->cassandra->cql3_query("CREATE TABLE users (user_name varchar,password varchar,gender varchar,session_token varchar,state varchar)");

This will try to create the table each time you run the code, if this is required by your application, change the query so it runs only if the table does not exists, so:

$query_result1 = Yii::app()->cassandra->cql3_query("CREATE TABLE IF NOT EXISTS users (user_name varchar,password varchar,gender varchar,session_token varchar,state varchar)");

Documentation: http://dev.mysql.com/doc/refman/5.5/en/create-table.html

cereal 1,524 Nearly a Senior Poster Featured Poster

Hello,

If I understood your problem you want to know how to connect your PHP script to Cassandra, correct? Check these links:

If you still have doubts, please post your code or at least add some details about your issue.

cereal 1,524 Nearly a Senior Poster Featured Poster

I would choose Laravel, I actually switched my new projects to that in April. I was going to start a new one and I was thinking to go back to Ruby on Rails, but then I decided to try Laravel and I like it, very much. I've been using CodeIgniter a lot in the last five years, for little to medium projects, it's easy to use and relatively easy to modify. But lately Ellislab dropped CodeIgniter development, they are seeking for a group interested in continuing the project:

From this point of view it's not a great news because there is no certainity of the future developments, and if it will ever support last versions of PHP.

My PROS list about Laravel 4:

  • good ORM library (Eloquent) which reminds me a lot Ruby on Rails, it's really easy to create relationships between tables, it supports soft deleting and you can use multiple databases concurrently
  • good command utility artisan which helps writing CLI scripts or asynchronous jobs, migrations scripts and resources
  • it's easy to create APIs, you can use HTTP verbs to interact with resources, it supports Auth Basic and you can also build your own mechanins by creating your filters
  • good template system: Blade
  • you can group and prefix routes, and also you can create named routes, I find this powerful because it gives you the ability to switch languages really easy
  • it's binded to Composer project which gives the ability to easily include third party …
cereal 1,524 Nearly a Senior Poster Featured Poster

You can change $data to a property of the class, so you can do:

class Page extends CI_Controller {

    // declare property
    protected $data;

    public function __construct()
    {
        parent::__construct();

        // define the property
        $this->data['assets'] = array(
                'style' => base_url().'assets/css/style.css',
                'connection' => base_url().'assets/images/connection.jpg',
                'collaboration' => base_url().'assets/images/collaboration.jpg',
                'solution' => base_url().'assets/images/solution.jpg',
                'connectionUrl' => base_url().'index.php/connection/',
                'collaborationUrl' => base_url().'index.php/collaboration/',
                'solutionUrl' => base_url().'index.php/solution/'
        );

        $this->data['navigation'] = array(
               'nav' => base_url().'assets/css/nav.css',
               'logo2' => base_url().'assets/images/logo2.png', 
               'index' => base_url(),
               'connectionUrl' => base_url().'index.php/connection/',
               'collaborationUrl' => base_url().'index.php/collaboration/',
               'solutionUrl' => base_url().'index.php/solution/',
               'foUrl' => base_url().'index.php/connection/fo',
               'wirelessUrl' => base_url().'index.php/connection/wireless',
               'cloudUrl' => base_url().'index.php/collaboration/cloud',
               'emailUrl' => base_url().'index.php/collaboration/email',
               'vconUrl' => base_url().'index.php/collaboration/vcon',
               'sharepointUrl' => base_url().'index.php/collaboration/sharepoint',
               'crmUrl' => base_url().'index.php/collaboration/crm',
               'voiceUrl' => base_url().'index.php/collaboration/voice',
               'networkUrl' => base_url().'index.php/solution/network',
               'systemUrl' => base_url().'index.php/solution/system',
               'surveillanceUrl' => base_url().'index.php/solution/surveillance',
               'searchbutton' => base_url().'assets/images/search button.jpg'
        );

    }

    public function index()
    {
        $this->data['title'] = 'title of this page';
        $this->load->view('templates/navigation', $this->data['navigation']);
        $this->load->view('homepage', $this->data['assets']); 
    }

    public function another_page()
    {
        $this->data['title'] = 'Another title';
        $this->load->view('templates/navigation', $this->data['navigation']);
        $this->load->view('anotherpage', $this->data['assets']); 
    }

}

Reference: http://www.php.net/manual/en/language.oop5.properties.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes you can, as sample:

DELIMITER //

CREATE PROCEDURE mytest(IN name VARCHAR(200))
    BEGIN
    select * from results where candidate = name;
    END//

DELIMITER ;

Then you just need to pass the parameter name:

call mytest('Sarah Smith');

Reference: http://dev.mysql.com/doc/refman/5.5/en/create-procedure.html

cereal 1,524 Nearly a Senior Poster Featured Poster

Does the table comment exists? The complete error should be something like:

mysql_fetch_array() expects parameter 1 to be resource, boolean given

Which means the query on line 19 returned false. In addition from line 12 to 14 you're not executing any query. So if the table does not exists the other queries will generate errors.

Also:

The query string should not end with a semicolon.

Reference: http://php.net/manual/en/function.mysql-query.php

cereal 1,524 Nearly a Senior Poster Featured Poster

I see you can get data also as xml or as json, this last seems to be malformed, so here's an example based on xml output:

<?php
    $url = 'http://chartapi.finance.yahoo.com/instrument/1.0/GOOG/chartdata;type=quote;range=5d/xml/';

    $f = file_get_contents($url);
    $xml = simplexml_load_string($f);

    # print everything
    print_r($xml);

Since you get an object array you can print a specific node by adding the node name:

print_r($xml->series);

From here it should be easy to collect data and create a chart.

cereal 1,524 Nearly a Senior Poster Featured Poster

Looking at your first example the increments should be by five, not by one, this is my test:

<?php

$key = 'never_before_used_key';
$cache = new Memcached;
$cache->addServer('127.0.0.1', 11211);
$cache->setOption(Memcached::OPT_BINARY_PROTOCOL, TRUE);
$cache->set($key,0,5);

$limit = 1000;
$i = 0;

while (true)
{
    $current = $cache->get($key);
    echo $cache->increment($key, 5). PHP_EOL;

    $i++;
    if($i > $limit || $key > $current) break;
}

I get this output:

5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
...

What version are you using? Mine is:

STAT version 1.4.13
STAT libevent 2.0.16-stable

You can see that by typing echo stats | nc -v 127.0.0.1 11211 | head

Not sure if this can be useful: https://code.google.com/p/memcached/issues/detail?id=320

cereal 1,524 Nearly a Senior Poster Featured Poster

Hello,

I'm wondering if I can get help to understand the behaviour of a PHP function: dns_get_record(). This returns an array with DNS records for the given domain name, here is an example of the output:

php > print_r(dns_get_record('php.net', DNS_TXT));
Array
(
    [0] => Array
        (
            [host] => php.net
            [type] => TXT
            [txt] => v=spf1 ptr ?all
            [entries] => Array
                (
                    [0] => v=spf1 ptr ?all
                )

            [class] => IN
            [ttl] => 272
        )

)

Now, if the DNS server returns multiple TXT records I get n keys ([0], [1], ...). What I'm not sure about is if the entries array will always return one entry. From the RFC 1035 I see the format of a TXT record is a text string.

But the PHP documentation does not mention the entries array nor it explains if it will always count one value. So I've searched the source file and this is the relevant part:

case DNS_T_TXT:
    {
        int ll = 0;
        zval *entries = NULL;

        add_assoc_string(*subarray, "type", "TXT", 1);
        tp = emalloc(dlen + 1);

        MAKE_STD_ZVAL(entries);
        array_init(entries);

        while (ll < dlen) {
            n = cp[ll];
            memcpy(tp + ll , cp + ll + 1, n);
            add_next_index_stringl(entries, cp + ll + 1, n, 1);
            ll = ll + n + 1;
        }
        tp[dlen] = '\0';
        cp += dlen;

        add_assoc_stringl(*subarray, "txt", tp, (dlen>0)?dlen - 1:0, 0);
        add_assoc_zval(*subarray, "entries", entries);
    }
    break;

I understand that add_assoc_* functions are adding the values to the subarray variable, that …

cereal 1,524 Nearly a Senior Poster Featured Poster

You can use find or tree for example, or mc to use something interactive. But if you explain why you cannot use ls maybe we can suggest the best solution for you.

cereal 1,524 Nearly a Senior Poster Featured Poster

Currently it runs twice. Change line 10 to:

$sent = mail($email, $subject, $message, $headers);

And line 13 to:

if($sent === TRUE)
{
    # success
}
else
{
    # failure
}
BadManSam commented: Ok, Thank You. It now is sent once. +1
cereal 1,524 Nearly a Senior Poster Featured Poster

Congrats! :)

JorgeM commented: thanks cereal +0
cereal 1,524 Nearly a Senior Poster Featured Poster

Intended font is supposed to be 16px at 100% so I think it's something on your end??

Confirmed, the problem was on my end, I was using Google Chrome 17.* on Ubuntu 12.04, my system gave me this as stable version, by adding another source I was able to upgrade to version 28, now it's all nice and shiny.

Solution steps:

  1. add new source:

    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
    
  2. add the key:

    sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
    
  3. update:

    sudo apt-get update
    

After the update the system will prompt for the installation of the latest stable version. Otherwise search it by typing: apt-cache search google-chrome

As note: Chrome 23.* and higher displays fine.

Thank you for your time Dani! :)

cereal 1,524 Nearly a Senior Poster Featured Poster

@szabizs

You don't need to add ALL to retrieve complete entries from those arrays, just:

print_r($this->input->get());

Same applies to post() method.

Szabi Zsoldos commented: thanks :) +4
cereal 1,524 Nearly a Senior Poster Featured Poster

It means "return only the first row of the result set", it's like using limit 1 in a query. If you open the link that I pasted above, you can access the documentation of this method.

cereal 1,524 Nearly a Senior Poster Featured Poster

Not sure if this helps, I checked the source of thr_lock.c as suggested here: http://dev.mysql.com/doc/refman/5.5/en/table-locking.html

It seems this depends on max_write_lock_count, once reached the limit, all the pending read locks are released. But it appears possible to change the behaviour of the queue system. This is what is written in the comments:

The current lock types are:
TL_READ         # Low priority read
TL_READ_WITH_SHARED_LOCKS
TL_READ_HIGH_PRIORITY   # High priority read
TL_READ_NO_INSERT   # Read without concurrent inserts
TL_WRITE_ALLOW_WRITE    # Write lock that allows other writers
TL_WRITE_CONCURRENT_INSERT
            # Insert that can be mixed when selects
TL_WRITE_DELAYED    # Used by delayed insert
            # Allows lower locks to take over
TL_WRITE_LOW_PRIORITY   # Low priority write
TL_WRITE        # High priority write
TL_WRITE_ONLY       # High priority write
            # Abort all new lock request with an error

Locks are prioritized according to:
WRITE_ALLOW_WRITE, WRITE_CONCURRENT_INSERT, WRITE_DELAYED,
WRITE_LOW_PRIORITY, READ, WRITE, READ_HIGH_PRIORITY and WRITE_ONLY

Locks in the same privilege level are scheduled in first-in-first-out order.

Lock types matches SELECT, INSERT, etc. modes:

  • SELECT [HIGH_PRIORITY]
  • INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY]
  • INSERT [LOW_PRIORITY | HIGH_PRIORITY] SELECT
  • UPDATE [LOW_PRIORITY]

The prioritized list seems to be in ascending order. So, according to this list, there's an order also in the write queue, where WRITE_ONLY is the higher privilege, however you can change the priority of a write lock to a lower level, check thr_downgrade_write_lock() starting at line ~1256. And check line ~682 for exceptions.

If you are in Debian/Ubuntu you can get the source by typing:

cereal 1,524 Nearly a Senior Poster Featured Poster

It depends on remote websites, something like facebook allows remote logins only with OAuth methods, this means a user of facebook doesn't need to share his own credentials (as the password) with your service, check this for more information: https://developers.facebook.com/docs/facebook-login/

In other cases (HTTP Basic Authentication & Co.) you can just send something like this username:password@website.tld to the correct resource and gain access.

Or you have to send a POST request with appropriate values to the script that usually receives the data of the login form.

In most cases you will use the cURL library, so if you want to try check the documentation: http://php.net/manual/en/book.curl.php

If you still have doubts post your code, we will try to help.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hello,

I've an array with different type of values: int, null, strings, arrays. I'm trying to remove nulls and empty strings, but I want to save ints, even when it equals to zero, so I tried with array_filter(), by default it will remove 0, '' and null, but by applying a callback it's possible to apply own rules. So I made few tests, and I'm getting unexpected results. The switch method will remove null and 0, while the if statements will remove the empty string and null, as I wanted. Now, I can use the if statements, but I don't understand why there's this difference between the two methods, even by removing the breaks it won't change results.

Any ideas why this is happening?

<?php

$array = array(
    0,                      # int
    null,                   # null
    '',                     # empty string
    'hello',                # string
    array('world')          # array
    );

$r['original'] = $array;

$r['switch_method'] = array_filter($array, function($value) {
    switch($value)
    {
        case is_string($value):
            return ! empty($value);
            break;
        case is_int($value):
            return true;
            break;
        case is_null($value):
            return false;
            break;
        case is_array($value):
            return count($value);
            break;
        default:
            return false;

    }
});

$r['ifelseif_method'] = array_filter($array, function($value) {

    if(is_string($value))
    {
        return ! empty($value);
    }

    elseif(is_int($value))
    {
        return true;
    }

    elseif(is_array($value))
    {
        return true;
    }

    elseif(is_null($value))
    {
        return false;
    }

    else
    {
        return false;
    }

});

var_dump($r);
echo PHP_EOL;

This is the output:

array(3) {
  ["original"]=>
  array(5) {
    [0]=>
    int(0)
    [1]=>
    NULL
    [2]=>
    string(0) ""
    [3]=>
    string(5) "hello"
    [4]=>
    array(1) {
      [0]=>
      string(5) "world"
    }
  }
  ["switch_method"]=>
  array(3) {
    [2]=>
    string(0) "" …
cereal 1,524 Nearly a Senior Poster Featured Poster

Change this line:

$srclocation = $_SERVER['SERVER_NAME']."/includes/key.php";

With:

$srclocation = $_SERVER['DOCUMENT_ROOT']."/includes/key.php";

SERVER_NAME will return the domain name, not the path.

cereal 1,524 Nearly a Senior Poster Featured Poster

That means you are using FastCGI, you can also use echo PHP_SAPI;

cereal 1,524 Nearly a Senior Poster Featured Poster

If there aren't any NULL values you could use CONCAT(). For example you have a table like this:

create table posts(
    id auto_increment primary key not null,
    title varchar(255) not null,
    body text not null,
    created_at datetime not null,
    updated_at datetime not null
) engine = myisam default charset=utf8;

Now if you want to save the hash to the same table you can add a field hash:

alter table posts add hash varchar(40) not null;

And perform a query like this:

update posts set hash = sha1(concat(id, title, body, created_at, updated_at));

This will run the hash against all the rows.

You can change method and use ARCHIVE engine instead, you cannot modify the entries once inserted, nor you can delete them. So it depends on your goals. You can also save the hash to another table (with archive engine) which will work as logger, in this case you will need an ID as foreing key, the hash and the date of when the check was performed, so you can perform multiple checks and compare results.

As I wrote it depends on you, if you have to hash existing data you don't need to pull it to PHP, you can run the queries directly in a MySQL client, otherwise if you're inserting data through a form, you can process the hash before sending everything to the database.

Or you can create a trigger. There are many solutions.

cereal 1,524 Nearly a Senior Poster Featured Poster

No problem. For example because this will make the property (variable) available inside the extended classes:

class Mailer extends Action
{        
    public function send_mail()
    {
        $emailTo = $this->userinfo['email'];

        # ... other code here ...
    }
}

It will be more easy to deal with data between classes. Check these links for more information:

cereal 1,524 Nearly a Senior Poster Featured Poster

First, remove global $userInfo; from line 33, and set it as public/protected/private variable at the top of the class:

class Action
{
    public $userInfo;

So, at line 47 you can write:

$this->userInfo = $stmt->fetch_array(MYSQLI_ASSOC);
cereal 1,524 Nearly a Senior Poster Featured Poster

Not:

`autod.mark`

But:

`autod`.`mark`

Also at line 29 there is no space between mudel.id and $where values, so it will generate:

... INNER JOIN mudel ON autod.mudel = mudel.idWHERE`autod.mark`=7;

Which is wrong. To see the error in the query change this:

if(!$cmd){
    $response['err'] = "Tekkis viga andmete küsimisel!";
    $response['success'] = false;
}

to:

if ( ! $cmd) {
    printf("Error message: %s\n", $connect->error);
    die(); # stop this test execution here.

    $response['err'] = "Tekkis viga andmete küsimisel!";
    $response['success'] = false;
}

# optional, but useful to avoid wrong executions
else
{
    # execute the query
}

If you're still using ajax then use the response array, but the lack of the ELSE statement, in case of wrong input/setting, will continue to execute the script generating errors like previous.

Reference: http://www.php.net/manual/en/mysqli.error.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Not tested, but if I'm not wrong this $cmd->bind_param("s", $where); will insert the value of $where as a string, so:

'autod.mark=7'

instead of:

`autod`.`mark`=7

If you try to display the error of the query you should get something like:

 Warning | 1292 | Truncated incorrect INTEGER value: 'autod.mark=7' 
cereal 1,524 Nearly a Senior Poster Featured Poster

use is a reserved word so, or you use backticks around the word or you alter the table.

In addition: the methods available for the form are POST, GET, PUT and other methods. REQUEST is a generic method used to retrieve data in PHP, don't use it in the method attribute, and avoid $_REQUEST if you can, because it allows a client to submit data also through a cookie.

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes. The RFC cited in PHP documentation explains that the semicolon is used to separate groups of mails, for example:

To: list-a: abc@localhost.tld, cba@localhost.tld;, list-b: admin@localhost.tld, info@localhost.tld;
cereal 1,524 Nearly a Senior Poster Featured Poster

Do you get the same effect with different browsers? I can think to an autofill issue here, if you're using HTML5 you can avoid it by adding autocomplete="off" to the input fields.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, then move this to the top of register.php file:

echo 'POST: ';
print_r($_POST);
echo '<br />SESSION: ';
print_r($_SESSION);
die();

place it right after <?php session_start(); and check if the values sent by $_POST and saved in $_SESSION are the same.

iamthwee commented: i think so too +14
cereal 1,524 Nearly a Senior Poster Featured Poster

@Atli
One to take in account is this: http://www.php.net/archive/2012.php#id2012-05-03-1
It referes to 5.3 and previous versions. Here's some info: http://www.daniweb.com/web-development/php/threads/422387/vulnerability-in-php-cgi

veedeoo commented: cool Cereal :) +8
cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, the problem is that set_value() doesn't consider if the validation runs true or false, usually you redirect() and so the POST array is resetted automatically, here we can force this action by extending /system/libraries/Form_validation.php, create /application/libraries/MY_Form_validation.php and paste this:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class My_Form_validation extends CI_Form_validation {

    public function __construct()
    {
        parent::__construct();
    }

    public function resetpostdata()
    {
        $obj =& _get_validation_object();
        foreach($obj->_field_data as $key)
        {
            $this->_field_data[$key['field']]['postdata'] = NULL;
        }
        return true;
    }

}
?>

After the validation runs true, call the method, as in this example:

if($this->form_validation->run() === FALSE)
{
    # . . .
}
else
{
    $this->form_validation->resetpostdata();

    # load view & other stuff
}

It should work fine, bye.

cereal 1,524 Nearly a Senior Poster Featured Poster

Maybe it's a connection problem? I don't see any evident issues, unless your server IP is banned or there is a DNS problem. If you have access to a terminal in your server, try to run this:

curl --head https://twitter.com/

It should return something like:

HTTP/1.1 200 OK
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
content-type: text/html; charset=utf-8
date: Sat, 13 Jul 2013 19:34:13 GMT
expires: Tue, 31 Mar 1981 05:00:00 GMT
last-modified: Sat, 13 Jul 2013 19:34:13 GMT
pragma: no-cache
server: tfe
...

Try also the dig command, to verify if this is a DNS issue, first run:

dig twitter.com

And then:

dig @8.8.8.8 twitter.com

The first will use default DNS settings, the second will query the DNS of Google.

cereal 1,524 Nearly a Senior Poster Featured Poster

Try this:

<?php

$url = 'https://twitter.com/darknille/status/355651101657280512';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);

curl_exec($ch);


if(!curl_errno($ch))
{
    $info = curl_getinfo($ch);

    echo $intReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close($ch);

    switch($intReturnCode)
    {
        case 200:
        case 302:
        case 304:
            echo "true";
            break;
        default:
            echo "false";
            break;
    }
}

?>

The problem with your first function is the callback.

cereal 1,524 Nearly a Senior Poster Featured Poster

I think you have to change 3900 to 3300, and change the second statment to compare cases between red and orange limits, here's an example:

<?php

date_default_timezone_set('Asia/Manila');

$current_time = "17:05";
$serving_time = "18:00";


echo "result: \t";
if(
    strtotime($current_time) <= (strtotime($serving_time) - 3600)
)
{
    echo 'red';
}
elseif(
    strtotime($current_time) <= (strtotime($serving_time) - 3300)
    &&
    strtotime($current_time) >= (strtotime($serving_time) - 3600)
)
{
    echo 'orange';
}
else
{
    echo 'blue';
}

echo PHP_EOL;
echo 'red limit: '."\t". date('G:i:s', strtotime($serving_time) - 3600) . PHP_EOL;
echo 'orange limit: '."\t". date('G:i:s', strtotime($serving_time) - 3300) . PHP_EOL;
echo PHP_EOL;

Then switch $current_time between:

$current_time = "17:00"; # red
$current_time = "17:05"; # orange
$current_time = "17:06"; # default
cereal 1,524 Nearly a Senior Poster Featured Poster

Change last line to:

echo ${$mystring}[0];

And it will work, otherwise it will refer to the name of the string myarray.

cereal 1,524 Nearly a Senior Poster Featured Poster

On live server you can use the Document Root to get an idea of the correct path, for example:

echo $_SERVER['DOCUMENT_ROOT'];

returns the server root, if this is something like /var/www/mysite/public_html/ and your upload directory is at the same level of public_html, then you can set:

$pdfFilePath = "/var/www/mysite/uploads/$filename";
cereal 1,524 Nearly a Senior Poster Featured Poster

You're welcome. When you close the browser the access permission will expire. Has security measure the .htpasswd file should be placed out of the web root, i.e. outside the DocumentRoot. Although this is "secure" it does not prevent brute-force attacks, to do that you should consider solutions like fail2ban:

But I don't know what kind of hosting plan are you using.

To check Apache config browse to /etc/apache2 and check the available files. If you don't have access to that directory check with your hosting documentation.

Consider this howto: http://httpd.apache.org/docs/current/howto/auth.html

ing commented: You're awesome! I appreciate your help. I'll look into fail2ban and see if I can access the apache2 directory. +0
cereal 1,524 Nearly a Senior Poster Featured Poster

To get the full path you can run pwd from the command line or run a PHP command as:

php -r 'echo __DIR__; echo PHP_EOL;'

It can be also a script file:

<?php
    echo __DIR__;
?>

Running this from the path in which is saved the .htpasswd file, will return the correct path to set. Another alternative is check the DocumentRoot value in your Apache config or by PHP:

<?php
    echo $_SERVER['DOCUMENT_ROOT'];

A relative path can be used in relation to the ServerRoot:

The AuthUserFile directive sets the name of a textual file containing the list of users and passwords for user authentication. File-path is the path to the user file. If it is not absolute (i.e., if it doesn't begin with a slash), it is treated as relative to the ServerRoot.

Note that DocumentRoot and ServerRoot are different, the first is for your files, the second refers the server installation.

The hash generated automatically by htpasswd is a MD5 digest, it starts by $apr1$, and is not the same of the typical MD5 hash, the result will be always different, for more information: http://httpd.apache.org/docs/current/misc/password_encryptions.html
So, it's not a problem to run the command in different systems and uploading the file. It will work.

AuthGroupFile /dev/null refers to a group of users, in this case is pointing to /dev/null, i.e. it's referring to an empty value. Unless there is a specific setup in your hosting company, AuthGroupFile is …

ing commented: Thank you! It's working now! The problem was I didn't know the absolute path. But your PHP script revealed it to me. Thank you! +0
cereal 1,524 Nearly a Senior Poster Featured Poster

If you have a static IP you can add it as allow rule:

<Limit GET POST PUT>
    Options -Indexes
    Order allow,deny
    Deny from all
    Allow from xxx.xxx.xxx.xxx
</Limit>

Otherwise you can use the Authenticantion modules: http://httpd.apache.org/docs/2.0/howto/auth.html

sash_kp commented: Static id,that's the problem in my case. I don't have one. Is there any other way to achieve the same functionality? Like,could we use php in order to get the current ip and auto set it in our .htaccess? +0
cereal 1,524 Nearly a Senior Poster Featured Poster

Replace the quotes that surrounds the field name 'town' with back ticks, so this:

$rs=mysql_query("select CommercialEnterprise_Email from commercialenterprise WHERE 'town' = 'Killkee'");

Becomes:

$rs=mysql_query("select CommercialEnterprise_Email from commercialenterprise WHERE `town` = 'Killkee'");

If you still get errors add mysql_error(): http://php.net/manual/en/function.mysql-error.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Hmm, I would do a test with file_exists() and make sure the file name and the path are correct, but as I said before I tried your configuration inside a controller and loads fine. So this probably does not help.

It may be the carriage return character? I just tried converting the pws file to Windows mode and it does not work anymore. While with Unix mode works fine. This can depend by the editor or by ftp transfer.

For example if the file is in a linux box, run:

cat -v word-list.aspell.lang.pws |head -n 20

the output should not return any ^M characters:

personal_ws-1.1 en 4 ^M
themouse^M
thecat^M
Daniweb^M
thedog^M

As said, the above will not work.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, change this:

personal_ws-1.1 en 869229 [utf-8]

First remove the square brackets, second this must match one of the *.cset files inside /usr/lib/aspell/, run this command to see the available encodings:

ls /usr/lib/aspell/*.cset

So, the above strings becomes:

personal_ws-1.1 en 869229 iso-8859-1

The path doesn't seem to be a problem, I've made a test with CI and works fine with your settings.

NOTE
Aspell does not seem to support utf-8:

the aspell utility will currently only function correctly with 8-bit encodings. I hope to provide utf-8 support in the future.

By consequence Pspell has the same problem. To use utf-8 you should consider the Enchant library: http://www.php.net/manual/en/intro.enchant.php