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

To me it seems to work fine:

$v0 = 3;
$v1 = 5;
$v2 = 7;

echo min( max(($v0 - $v1), 0), $v2);

$v0 - $v1 = -2 so max() between -2 and 0 is 0, min() result will be 0, inverting $v0 and $v1 will output 2 as expected. Or am I wrong?

cereal 1,524 Nearly a Senior Poster Featured Poster

Try:

$this->db->where('active',1)->order_by('date_added','desc')->limit($num, $start)->get('posts');

When selecting all the fields, the select() method is not needed.

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

Can you provide some code? Here's my test:

<?php

$string = "Hello we're checking &amp; testing this brand-new /string/";

$old = array(' ', '/', 'amp;', "'");
$new = array('-', '-', '-', '-');

$string = str_replace($old, $new, $string);
$string = implode('-', array_filter(explode('-',$string)));
echo $string;
echo PHP_EOL;

Outputs: Hello-we-re-checking-&-testing-this-brand-new-string

It works also without $new array, since the character to replace is the same for all:

echo str_replace($old, '-', $string);
cereal 1,524 Nearly a Senior Poster Featured Poster

Change the wrapping quotes to double quotes:

$old = array(' ', '/', 'amp;', "'");

Or escape the quote:

$old = array(' ', '/', 'amp;', '\'');

and it should work.

cereal 1,524 Nearly a Senior Poster Featured Poster

So it was also a size issue? Good to know.

cereal 1,524 Nearly a Senior Poster Featured Poster

Works fine here.

cereal 1,524 Nearly a Senior Poster Featured Poster

No problem, I did a test to be sure, I used italian, spanish and french words and some random characters, just to see if there was a match, I also removed PSPELL_RUN_TOGETHER, but it works fine.

Here's the code: http://pastebin.com/JbPYfyrb

Is this running by terminal? Because this procedure showed me a problem:

php index.php CONTROLLER_NAME METHOD ARG1

Here's the error:

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  pspell_save_wordlist(): pspell_save_wordlist() gave error: The file "/home/username/application/controllers/includes/lib/custom.pws" can not be opened for writing.</p>
<p>Filename: controllers/dw.php</p>
<p>Line Number: 16</p>

</div>

It refers to:

pspell_config_personal($config, APPPATH . 'controllers/includes/lib/custom.pws');

But the real path of the file is:

/var/www/test/application/controllers/includes/lib/custom.pws

not /home/.../ as in the error. In order to make it work from terminal I had to remove APPPATH. Anyway, tomorrow I will try a fresh install of CI, just to be sure this is not a reflection of one of my edits... :D

Hope someone else, in the meanwhile, helps you to find a solution.

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

cereal 1,524 Nearly a Senior Poster Featured Poster

The format for PWS files is one word per line, as you done. In Ubuntu the dictionaries used by pspell are in /usr/lib/aspell/, but you can use this command from a terminal to read the configuration and retrieve the correct path:

aspell config |grep -i data-dir

Regarding the replacement files:

The replacement word list has each replacement pair on its own line in the following format:
misspelled_word correction

For more info check these links:

cereal 1,524 Nearly a Senior Poster Featured Poster

As side note: Tor changes the IP every 10 minutes or so by default. But the users can force the change at each request. In this particular case there could be a problem with the matching IPs.

cereal 1,524 Nearly a Senior Poster Featured Poster

There is an internal tool since MySQL 5.1.4, it is mysqlslap: http://dev.mysql.com/doc/refman/5.1/en/mysqlslap.html

From a terminal you can try something like:

mysqlslap -uUSERNAME -pPASSWORD -h localhost --create-schema="DATABASE NAME" --query="SELECT aDate FROM range_dates WHERE aDate BETWEEN @minDate AND @maxDate;" --concurrency=50 --iterations=200

An example of output:

Benchmark
Average number of seconds to run all queries: 0.098 seconds
Minimum number of seconds to run all queries: 0.094 seconds
Maximum number of seconds to run all queries: 0.164 seconds
Number of clients running queries: 50
Average number of queries per client: 1

While with MySQL 5.5+ there are more options: http://dev.mysql.com/doc/refman/5.5/en/optimize-benchmarking.html

cereal 1,524 Nearly a Senior Poster Featured Poster

Check the Debian documentation: http://www.debian.org/doc/

It's quite good.

cereal 1,524 Nearly a Senior Poster Featured Poster

Sure you can, you can also convert the CREATE statements to InnoDB or to Memory, it will work. The only problem comes if you decide to use TEMPORARY tables because:

You cannot refer to a TEMPORARY table more than once in the same query.

Which is what happens in range_dates procedure with range_numbers table.

cereal 1,524 Nearly a Senior Poster Featured Poster

Unfortunately this is a restriction:

Subqueries cannot be used in the FROM clause of a view.

But you could try with procedures, first you install the tables range_numbers and range_dates:

delimiter //
drop procedure if exists range_tables//
create procedure `range_tables`()
    language sql
    deterministic
    sql security definer
    BEGIN
    DROP TABLE IF EXISTS `range_numbers`;
    CREATE TABLE range_numbers (a int(1)) ENGINE=MyISAM;
    INSERT INTO range_numbers (a) values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
    DROP TABLE IF EXISTS `range_dates`;
    CREATE TABLE `range_dates`(`aDate` DATE not null) ENGINE=MyISAM;
    END//

call range_tables//

Then you install range_dates procedure:

drop procedure if exists range_dates//
create procedure `range_dates` ()
    language sql
    deterministic
    sql security definer
    comment 'dates'
    begin
    TRUNCATE `range_dates`;
    INSERT INTO `range_dates` (aDate) SELECT @aDate := (@maxDate - INTERVAL (a.a+(10*b.a)+(100*c.a)+(1000*d.a)) DAY) FROM
      (SELECT a FROM range_numbers) a,
      (SELECT a FROM range_numbers) b,
      (SELECT a FROM range_numbers) c,
      (SELECT a FROM range_numbers) d,
      (SELECT @minDate := DATE_FORMAT(SYSDATE(), '%Y-01-01'), @maxDate := DATE_FORMAT(DATE_ADD(SYSDATE(), INTERVAL 1 YEAR), '%Y-01-01')) e;
    end//

delimiter ;

Go to populate the table range_dates:

call range_dates;

And finally you execute the query:

SELECT aDate FROM range_dates WHERE aDate BETWEEN @minDate AND @maxDate;

Since the tables are MyISAM you need to run only call range_dates; before of the query, this will set the variables and the new rows in range_dates table.

Disclaimer: I'm not sure it's the best solution, it's more a test.

cereal 1,524 Nearly a Senior Poster Featured Poster

Provide the code, or at least an example of what is not working for you, it could be a problem of headers. Also have you checked sendmail error log? Does the sender email exists? Do you receive any responses from mail daemons?

cereal 1,524 Nearly a Senior Poster Featured Poster

Keep in mind that $_POST works as an array, so if you want to use one of the keys, you have to write:

$_POST['password']

not $_POST[password] which lacks of quotes. The same applies to $_POST[sbg]. For this reason you are probably getting d41d8cd98f00b204e9800998ecf8427e from:

$pass=md5($_POST[password]);

Because it appears as a false or null. That should also create a Notice like this:

Notice: Use of undefined constant password - assumed 'password'

So, in development stage enable error reporting, it will help you.

Regarding the differecens between PHP4 and PHP5, check the manual: http://php.net/manual/en/migration5.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Check the API of tumblr: http://www.tumblr.com/docs/en/api/v2#blog-info
In the section Blog Info there are many methods to retrieve the information you're looking for.

cereal 1,524 Nearly a Senior Poster Featured Poster

Regarding the date try:

date('d-m-Y', mktime(0, 0, 0, date("m"), date("d") + $_POST['exdays'], date("Y")));

Concerning the second question, you can use json_encode() to convert the array to a string and so, you can save it as varchar or text type, otherwise you need a blob type.

Edit
Sorry Webville, I just saw your reply, bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

You're welcome. Since I don't know much about Wordpress, I cannot help more.
Try this: http://codex.wordpress.org/WordPress_in_Your_Language it may be useful.

cereal 1,524 Nearly a Senior Poster Featured Poster

In addition to previous notes, the direction of the text depends on the HTML dir attribute, an example of multilanguage page:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>sample arabic language</title>
</head>
<body>
    <p lang="ar" dir="rtl">مرحبا</p>
    <p>hello</p>
</body>
</html>

If your page is not mixed and you have only Arabic, then change it to:

<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="utf-8">
    <title>sample arabic language</title>
</head>
<body>
    <p>مرحبا</p>
</body>
</html>

The rtl value stands for right-to-left. I don't know Wordpress, plus I don't know if you're using an uri segment to define the language in use, but it should be easy to set lang and dir attributes on the fly.

cereal 1,524 Nearly a Senior Poster Featured Poster

If you can execute a shell, search the library:

find / -name *pdo*so 2>/dev/null

the 2>/dev/null segment will suppress the errors (usually due to permessions), you can remove it if you want to get all the output. After you save the config file remember to reload the server.

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

MySQL library doesn't support multiple queries, so if you set a MySQL variable as @codCliente it will not be considered by the subsequent query. In order to do so, you have to use MySQLi or PDO libraries.

In other words:

$q = mysql_query('SELECT LAST_INSERT_ID() INTO @codCliente');

will not work. Instead this should work:

<?php

$dbhost = 'hostname';
$dbname = 'database';
$dbuser = 'username';
$dbpass = 'password';

$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", "$dbuser", "$dbpass");

# insert query
$conn->query("INSERT INTO clienti SET nominativo = 'Rossi Mario', indirizzo = 'via Manzi, 2 - 00153 Roma', telefono = '06 86123920'");

# set variable @codCliente
$conn->query('SELECT LAST_INSERT_ID() INTO @codCliente');

# retrieve @codCliente
$cod = $conn->query('SELECT @codCliente as codiceCliente')->fetch();

echo $cod['codiceCliente'];

More information:

cereal 1,524 Nearly a Senior Poster Featured Poster

If you have access to the mail directory you can use Plancake library: https://github.com/plancake/official-library-php-email-parser

It will parse the files into an object, from there you can store it into the database. If you don't have direct access, you may want to add IMAP library to get the messages: http://www.php.net/manual/en/ref.imap.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Basically:

mysql_query('INSERT QUERY HERE');
$codCliente = mysql_insert_id();

Here's the link to the manual: http://php.net/manual/en/function.mysql-insert-id.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Move these:

$image_value = array();
$description_value = array();

outside the while statement, otherwise the array resets after each loop. Also you can avoid the use of array_push() by writing:

while($row = mysql_fetch_array($result))
{
    $image_value[] = $row['image_id'];
    $description_value[] = $row['description'];
}
cereal 1,524 Nearly a Senior Poster Featured Poster

You can do what LastMitch suggested previously. In this case, Apache will handle the mime of the file and take care to send the appropriate headers to the browser.

Sometimes, however, you may want to hide the source directory and disallow direct access; in these cases you can create a script that displays the image:

<?php

$path = './hidden/path/';
$name = pathinfo(trim($_GET['name'],'/'), PATHINFO_BASENAME);

if( ! file_exists($path.$name))
{
    die('Not found');
}

$file = file_get_contents($path.$name);

# set mime type for jpeg files
header("Content-Type: image/jpeg");
echo $file;

?>

And use it like this:

<img src="/script/index.php?name=image001.jpg" />

More can be done to block the access to the source directory and to hide the script name by using mod_rewrite in .htaccess files, but this is off topic.

Anyway it's not a good solution unless you really need it, because it will force the server to include the PHP engine in the request of a static file.

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

No problem for the questions, don't worry. How to show the data it's up to you, try to execute a select query:

SELECT * FROM $db_table

and loop the result set. To achieve this task read:

And check the examples, if you still have problems then post the code.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, it's easier: create the folder listings and make sure is not read-only, if I remember good, you can check it by right clicking and selecting properties. After that it should work fine.

Usually in remote servers configurations, you should check for User/Group in the Configuration > apache2handler section.

cereal 1,524 Nearly a Senior Poster Featured Poster

No, you have to create the directory in the server, and make sure it is writable by the script: this means writable by the user which runs the server, for Apache usually this is www-data. But you can check it by running phpinfo().

If you are using a remote server you can create the directory through ftp or through mkdir() function. In the first case the directory will be owned by the ftp user, in the second case by the Apache user.

This translates into two different permissions settings for the directory: 777 or 755. If you want to use mkdir then run:

$dir = './listings/';
if( ! file_exists($dir))
{
    mkdir($dir, 0755);
}
cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, you get a blank page because the submit input field lacks of the name attribute: since you're testing for $_POST['submit'] you have to add this attribute; second problem: the name attribute of the file input field is file instead of Photo as expected in your $_FILES['Photo'].

So, in order to work change the form to:

<form action="" method="POST" enctype="multipart/form-data">
    <input type="file" name="Photo"/>
    <br />
    <input type="submit" name="submit" />
</form>
cereal 1,524 Nearly a Senior Poster Featured Poster

Use reload:

sudo service apache reload

in practice Apache will perform a graceful restart, it is the same of running:

apachectl -k graceful

it means that will finish to serve the current requests before restarting.
For more information and options check: http://httpd.apache.org/docs/2.2/en/stopping.html

cereal 1,524 Nearly a Senior Poster Featured Poster

Check also parse_url() it will return an array of the url components, included the hashmark # fragment:

Bye.

cereal 1,524 Nearly a Senior Poster Featured Poster

Show us the form and the current script.

cereal 1,524 Nearly a Senior Poster Featured Poster

No, once you have defined the image_name in the table structure, as suggested by LastMitch, MySQL will handle the input and return an error if something went wrong. So you don't need to set anything else to make the update query work.

When in doubt use mysql_error():

mysql_query($query) or die('Error, query failed: '. mysql_error());

It will help to understand errors.

cereal 1,524 Nearly a Senior Poster Featured Poster

Consider SwiftMailer library, it works fine and once installed it's easy to use:

In particular check the send method and the batch mode at the end of the page.

The mail() function is not the best choice for large sets because it is resource expensive and it doesn't offer full control about the headers.

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes, it should work fine:

"UPDATE `tablename` SET `image_name` = '$filePath' WHERE `id` = 1"

However I prefer to save only the filename, because the path it can be an internal directory structure, it can change, and because the same name can used to point to different directories (images, thumbs100x100, thumbs200x200, ...) and retrieve different versions of the image, so I would use $fileName instead of $filePath:

"UPDATE `tablename` SET `image_name` = '$fileName' WHERE `id` = 1"
cereal 1,524 Nearly a Senior Poster Featured Poster

If you're trying to insert data then change the above query to:

"INSERT INTO `tablename` (`image_name`) values('$img_file')"

This will create a new entry in the table. While if you want to update an existing row, for example the row with id 1, use an update statement:

"UPDATE `tablename` SET `image_name` = '$img_file' WHERE `id` = 1"

Check MySQL manual for more information:

cereal 1,524 Nearly a Senior Poster Featured Poster

You could use file_put_contents() to save the array to the text files:

file_put_contents('questions.txt', json_encode($questions));

Then use file_get_contents() to get the arrays from the files and use array_combine() to match them. As suggestion use json_encode() to save data to txt files, and then just run this to retrieve:

$questions = json_decode(file_get_contents('questions.txt'),TRUE);

For more information check the manual:

cereal 1,524 Nearly a Senior Poster Featured Poster

The difference is that if bar is null isset() will return FALSE, while array_key_exists() will still return TRUE:

$foo['bar'] = NULL;

echo isset($foo['bar']) ? 'true':'false';
echo array_key_exists('bar',$foo) ? 'true':'false';

So it depends on your intentions.

diafol commented: never knew that +14
cereal 1,524 Nearly a Senior Poster Featured Poster

Line 32:

<option value="<?php echo $ho('interior_house_id');?>"><?php echo $ho['interior_house_desc'];?></option>

Change $ho('interior_house_id') to $ho['interior_house_id'] and it should work. Also I suggest you to use $this->input->post() instead of $_POST since it sanitized by the framework (if $config['global_xss_filtering'] = TRUE;). Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster
This is for Laravel 3.*
Hello,

With this snippet I'm providing a simple way to automatically filter Input::get() and Input::old(). To achieve this result we need to make few changes:

  • extend Input and Redirect classes by creating new files in application/libraries/, the files are: input.php and redirect.php;
  • comment the aliases of these classes in application/config/application.php file, otherwise the application will ignore the extended libraries.

The extended Input class overwrites Input::query() so it can use the new method Input::sanitize(), which is where you can place your filters, in this example I'm using filter_var_array():

public static function sanitize($array)
{
    $result = filter_var_array($array, FILTER_SANITIZE_STRING);
    return $result === false || is_null($result) === true ? array() : $result;
}

But it can be rewritten as you like, this method is just a container for your prefered approach, it can be an implementation of CodeIgniter xss_clean() method, or you can simply use strip_tags(). Just make sure to return an array of keys and values.

Below there is a version working with the HTMLPurifier library, in this case I'm using the porting published in the bundles archive. Once installed, you can change the above method with:

/**
 * Filter the query string array
 *
 * <code>
 *      // Return an empty array if data is removed
 *      $array = Input::sanitize(array('msg' => 'hello'));
 * </code>
 *
 * @param  array   $array
 * @param  array   $input
 * @return array
 */

public static function sanitize($array, $input = array())
{
    $purifier = IoC::resolve('HTMLPurifier');
    $array = filter_var_array($array, …
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,
in order to help we need details. Post some error codes or at least the code block which seems to create the problem. Also check server, database and PHP errors logs.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,
take a look at Google Custom Search API: https://developers.google.com/custom-search/v1/overview

Once you get results you can scan the links in search of microformats or metadata. To do that you will need a microformat parser or something like get_meta_tags() for metadata. Then, if you want more results or compare data, you could add a callback to check the contact page and try to parse the <address> tag or search for emails and phone numbers.. it'a a bit tricky.

cereal 1,524 Nearly a Senior Poster Featured Poster

Yup, it works fine. It's loaded by the download_helper.php in system/core/helpers.

A tip: when using $config['compress_output'] = TRUE add @ob_end_clean() above of force_download(). Otherwise, in some cases, it returns corrupted files.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,
If the directory down/ is not directly accessible by web use $this->input->server('DOCUMENT_ROOT') instead of base_url().

Also, use file_exists() to be sure about the requested file and pathinfo() to grab the filename from $this->input->post('filedown'), otherwise a user can execute ../../../random_file:

$filedown = pathinfo($this->input->post('filedown'),PATHINFO_BASENAME);
$datas = $this->input->server('DOCUMENT_ROOT').'/down/'.$filedown;
if(file_exists($datas))
{
    force_download($filedown, $datas);
}
else
{
    // error action
}