cereal 1,524 Nearly a Senior Poster Featured Poster

To paste code I usually place the cursor in a new line and then I press TAB once, for example:

/**
 * Sign Out
 * @return void
 */
public function getOut()
{
    Auth::logout();
    return Redirect::route('sign_in');
}

Usually, it does not require any other adjustment because, in my editor, I always indent the code. Otherwise you have to select the pasted code and press TAB. By pressing Shift Tab, instead, you remove one tab space. So you can adjust the code block as you like. Hope it helps, bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi all,

James you can send an email to Gmail SMTP, you don't need sendmail to do this because you're going to connect directly to the SMTP server. Check this example:

Which makes uses of PHPMailer library:

You can do it without: you need to use PHP sockets and you have to create a script that listens to the replies of the SMTP server, otherwise it will not work. Using a library like PHPMailer is probably the best solution. Bye!

Kyle Wiering commented: Great post! +2
cereal 1,524 Nearly a Senior Poster Featured Poster

@Wojciech_1

Ctrl Tab focuses the next tab, Ctrl Shift Tab the previous.

cereal 1,524 Nearly a Senior Poster Featured Poster

I just tried Ctrl+tab and it jumped to the next browser tab.

Same here on Chrome. In Ubuntu Alt Tab is used to switch the windows in the same workspace. Maybe Shift Tab? It seems free, at least in Ubuntu.

cereal 1,524 Nearly a Senior Poster Featured Poster

Sorry for the update, the live example link for method #2 was wrong:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, create a container for #box5, then you can use two methods.

Method 1

Move the text outside the opaque element and move it over, something like this:

<div id="box">

    <div id="box5"></div>

    <div id="box5-p">
        This text is normat text over opacity background
    </div>

</div>

Styles:

#box
{
    position: relative;
    width:250px;
    height:250px;
}

#box5 {
    margin:10px;
    width:100%;
    height:250px;
    border:1px solid green;
    overflow:auto;
    float:left;
    background-size:50%;
    background: url(https://developer.mozilla.org/media/img/mdn-logo.png);
    background-repeat:no-repeat;
    background-position:center;
    padding:20px;
    opacity: 0.2;
    z-index:99;
}

#box5-p {
    position: absolute;
    top:20px;
    left:20px;
    opacity:1;
    color:red;
    font-size:18;
    font-weight:bolder;
    z-index:100;
}

Live example: http://jsfiddle.net/qe3xpzhn/

Method 2

Use the #box5::after rule where you define the background and the opacity level, something like:

<div id="box">

    <div id="box5">
        This text is normat text over opacity background. This text is normat text over opacity background.
    </div>

</div>

And the styles:

#box
{
    position: relative;
    width:250px;
    height:250px;
}

#box5 {
    margin:10px;
    width:250px;
    height:250px;
    border:1px solid green;
    overflow:auto;
    position: relative;
    float:left;
    padding:20px;
}

#box5::after
{
    content: "";
    opacity:0.2;
    background-image:url(https://developer.mozilla.org/media/img/mdn-logo.png);
    background-repeat:no-repeat;
    background-position:center;
    background-size:50%;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    position: absolute;
    padding:20px;
    overflow:auto;
}

Live example: http://jsfiddle.net/2sc4zpjx/
Source: https://css-tricks.com/snippets/css/transparent-background-images/

mattster commented: +1 +7
cereal 1,524 Nearly a Senior Poster Featured Poster

Also @Nilesh_4

Hi! In PHP you can use both. But there's to say that && has an higher precedence than AND, which defines how the conditions are grouped. So for example:

<?php

    $a = true;
    $b = true;
    $c = false;

    $d = $a === true && $b === true AND $c === true;
    echo var_dump($d);

    $d = $a === true && $b === true && $c === true; 
    echo var_dump($d);

Outputs:

test #1
bool(true)

test #2
bool(false)

If the conditions are set into an IF statement, instead of being assigned to a variable, the expression returns false in both cases.

More information here:

cereal 1,524 Nearly a Senior Poster Featured Poster

Works fine for me, try to trim the input, if you get a space at the beginning or at the end of the string then the comparison will fail, so before the statements do:

$_POST = array_map('trim', $_POST);

Docs: http://php.net/array-map

cereal 1,524 Nearly a Senior Poster Featured Poster

In addition, there is a small typo with quotes:

$_POST['accommodation"]

Use single quotes or double quotes, not both together:

$_POST['accommodation'] # or
$_POST["accommodation"]

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi all,

music for me is something special, I'm always in search for new music: new to my ears.

I listen primarly Bach: search for Goldberg Variations or the Toccatas by Glenn Gloud, the Cello Suites by YoYo-Ma and Sviatoslav Richter's concerts. Or Chopin by Brigitte Engerer. Rachmaninoff by Richter is also awesome.

Then Philip Glass and the Reworks made by other artists, Moondog, the Ukulele Orchestra of Great Britain, Fat Freddy's Drop, Ratatat, Moderat, Hjálmar, Ananda Shankar, Bob Dylan, Zoe Keating, Balanescu Quartet, CYNE, The World Inferno Friendship Society, Yusef Lateef, Robbie Basho, Arvo Pärt, Sufjan Stevens, Neon Indian, The Flamming Lips, La Femme, Devotchka, La Rue Ketanou just to name few.

Defining the favourite is difficult, depends on the mood and situations (long runs or while writing code), in those cases I can listen a specific song in loop for hours...

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, by writing include('cutenews/search.php'); you define the position of the search script in relation with the calling script, so if you have:

/calling.php
/cutenews/search.php

it will work, but if this is the situation:

/cutenews/calling.php
/cutenews/search.php

Or something different, like this:

/other/calling.php
/cutenews/search.php

It will fail. If the cutenews directory is in the document root of the web server then try:

`include($_SERVER['DOCUMENT_ROOT'] . '/cutenews/search.php');`

This will generate an operative system absolute path. When the include function fails you should see a warning, check the error reporting level or, while debugging, set it to -1:

It should help to fix the issue.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

are you accessing the website through the IP? I ask this because the function that checks the path is this:

// Since 2.0: security reason
function check_direct_including($incln)
{
    global $PHP_SELF;
    $Uri = '//'.dirname( $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
    if (strpos(getoption('http_script_dir'), $Uri) !== false && strpos($PHP_SELF, $incln) !== false)
        die(proc_tpl('help/manual/wrong_include', array('category' => REQ('category','GPG'))));
}

As you see, it is using $_SERVER['HTTP_HOST'] to populate the $Uri variable and the getoption() function to extract the correct path to the file.

Now: if you access the website through the IP address the browser will not set the HTTP_HOST variable, yes this even if is declared as $_SERVER variable is set by the client, and so the check could fail.

If you want a better control I would suggest to patch it by using $_SERVER['SERVER_NAME'], this value is defined in the VirtualHost section of your Apache configuration file.

Code reference: https://github.com/CuteNews/cutenews-2.0/blob/master/core/core.php#L2059

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

you need at least MySQL 5.1.5 to import XML, otherwise you have to check if a UDF (user defined function) was developed to support old versions. In the documentation you can find a comment (bottom of the page) that suggests a workaround, sincerly I wouldn't use it. If possible instead try to upgrade the database:

cereal 1,524 Nearly a Senior Poster Featured Poster

In addition: $values['books'] is an array where the index key is the book_id, for example:

[books] => Array
    (
        [38] => Array
            (
                [book_id] => 38
                [title] => Alexander of Macedon, 356-323 B.C. : a historical biography.
                [author_lf] => Green, Peter
                [author_fl] => Peter Green
                [author_code] => greenpeter
                [ISBN] => 0520071654
                [ISBN_cleaned] => 0520071654
                [publicationdate] => 1991
                [entry_stamp] => 1124597764
                [entry_date] => Aug 21, 2005
                [copies] => 1
                [rating] => 5
                [language_main] => eng
                [language_secondary] => 
                [language_original] => 
                [hasreview] => 1
                [dateacquired_stamp] => 0
                [dateacquired_date] => Dec 31, 1969
                [cover] => http://pics.cdn.librarything.com/picsizes/44/87/448711e34ba0018597835424e67414141414141.jpg
                [bookreview] => This was my introduction to Alexander the Great. I still think it's the best, although Robin Lane Fox's...
                [bookreview_stamp] => 1229121379
                [bookreview_date] => Dec 12, 2008
                [tags] => Array
                    (
                        [0] => favorite
                        [1] => alexander the great
                    )

            )

So, to see the results you have to loop it:

foreach($values['books'] as $book_key => $book_value)
{
    echo $book_value['title'];
}
broj1 commented: Well spotted +11
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

from the error message it seems the page includes PHP, if affirmative then check that the variables are correctly closed, for example here is missing the semicolon:

<?php

    $a = 'hello'

?>
<!DOCTYPE html>
...

And will generate the same parse error, pointing the end of the file even if the variable is on the top of the file.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi all,

I still haven't tried PHPStorm as I usually prefer simple editors, among these I'm really happy with Sublime, right now.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

it could be the mime-type or the column table size, be sure to not truncate the input. If using a blob column type then this can support up to 65536 bytes. To save more data use mediumblob which supports up to 16MB or longblob which supports up to 4GB.

The same applies if you're saving them as encoded strings, use mediumtext or longtext instead of text.

Docs: http://dev.mysql.com/doc/refman/5.6/en/storage-requirements.html

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, are you using autocomplete="off" in your form tag?

cereal 1,524 Nearly a Senior Poster Featured Poster

It seems correct to me.

Are you loading other helpers? Are you still using CaddLatihan controller? There you have a form to add the articles, which uses the same helper to open the form tag (which also adds a hidden csrf field). Is this still working?

cereal 1,524 Nearly a Senior Poster Featured Poster

Heh heh. 40 posts later. Going for the record?

Heh! just trying! :D

@davy can you show us your Cdelete controller?

cereal 1,524 Nearly a Senior Poster Featured Poster

@davy this is the same error of last week, are you loading the form helper in the Cdelete controller? It returns undefined function because it does not read the resource.

Besides, it was late when I posted the fixes and I made a mistake in the model, change the line marked wrong:

public function delete_news()
{
    $this->id = $this-delete->post('id'); # <- wrong
    return $this->db->delete('latihan', $this); 
}

With this:

$this->id = $this->input->post('id'); # <- correct
cereal 1,524 Nearly a Senior Poster Featured Poster

Yes, it happens because of your view page, you are not sending the id through any form, in order to work you have to change few things:

  • add a form for each delete button;
  • save the article id into an hidden input field;
  • modify the delete_news() method model to receive only the id, since isi seems to be a text field you need only the id.

So this:

<?php foreach($records as $row): ?>
<tr>
    <td><?php echo $row->id; ?></td>
    <td><?php echo $row->isi; ?></td>
    <td><button type="button" onClick="parent.location='/ci2/index.php/cdelete/'">Delete</button></td>
</tr>    
<?php endforeach; ?>

Becomes:

<?php foreach($records as $row): ?>
<tr>
    <td><?php echo $row->id; ?></td>
    <td><?php echo $row->isi; ?></td>
    <td>
        <?php echo form_open('/cdelete/delete'); ?>
        <input type="hidden" name="id" value="<?php echo $row->id; ?>" />
        <button type="submit">Delete</button>
        </form>
    </td>
</tr>    
<?php endforeach; ?>

Note: I added the controller method to the url, you were pointing the index, that way the request will never work, the updated version will call the delete() method of the controller:

/cdelete/delete

The model:

public function delete_news()
{
    $this->id = $this-delete->post('id');
    $this->isi = $this-delete->post('isi');
    return $this->db->delete('latihan', $this); 
}

Becomes:

public function delete_news()
{
    $this->id = $this-delete->post('id');
    return $this->db->delete('latihan', $this); 
}

And don't forget to fix the validation rules in your controller, you don't need to check for isi anymore, so remove line 24 in your controller:

$this->form_validation->set_rules('isi', 'isi', 'required');
cereal 1,524 Nearly a Senior Poster Featured Poster

Here there is an error:

$this->id = $this-delete->post('id');
$this->isi = $this-delete->post('isi');

You're trying to access the input, so you must use the input class:

$this->input->post('field_name');

So, change the line 22 and 23 in your delete() method model to:

$this->id = $this->input->post('id');
$this->isi = $this->input->post('isi');

Also, does $this refers to --> the database ? I wonder

$this is a pseudo-variable used to access parent and self methods and properties, in CodeIgniter it gives you the ability to access the shared resources (libraries, helpers) loaded at each request. For more information read this:

cereal 1,524 Nearly a Senior Poster Featured Poster

Thanks for sharing! I tested your class and I like it, consider to add a passphrase to allow different results, it could be helpful.

You may want to check Hashids, it's very similar to your concept: http://hashids.org/

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

you actually get the result, just loop it:

$result = $pdo->query("SELECT * FROM posts");

foreach ($result as $key => $value)
    echo $value['title'];

echo 'Total: '. $result->rowCount();

It's not visible through print_r() because the statement is an iterable object, if you want the full array use fetchAll():

print_r($result->fetchAll());

As second parameter you can define the fetch mode, for example:

$result = $pdo->query("SELECT * FROM posts", PDO::FETCH_ASSOC);

For more information check the PDOStatement class:

Also, read the following article, at the end there is a paragraph dedicated to PDO::FETCH_CLASS method, which explains a bit how flexible can be a PDO statement:

lps commented: nice detailed explainations +4
terryds commented: Thanks for your nice answer +0
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, use trim() to remove the pending comma:

echo trim('a,b,c,', ',');

The same can be done at query level:

select trim(TRAILING ',' FROM 'a,b,c,');

Docs:

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes you can, SimpleXML is going to create an object of that string, so it should be easy, for example:

print_r($xml->Course);

Or to get a specific property:

echo $xml->Course->CourseName;
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi!

Apparently you get NULL, but PHP is also sending a warning:

Warning: simplexml_load_string() expects parameter 1 to be string, object given

because $values->getCourseDetailResult is an object, and outputs:

stdClass Object
(
    [any] => XML is here ...
)

So change your previous:

$xml = simplexml_load_string($values->getCourseDetailResult);

To:

$xml = simplexml_load_string($values->getCourseDetailResult->any);

and it should work fine.

cereal 1,524 Nearly a Senior Poster Featured Poster

the form gets posted it will only return the first variable that i place in the paranthesis like

It happens because the message() method takes only one argument. In order to work correctly you should write something like this:

$this->email->from('contact@domain.tld', 'From WebSite');
$this->email->reply_to($email, $name);
$this->email->to('me@domain.tld');
$this->email->subject('Message from contact form');
$this->email->message($message);
$this->email->send();

Important note: the from header is used to define the sender from YOUR domain, not the user that is contacting you, which instead is defined in the reply_to header, i.e. it defines the email address of your domain allowed to send emails. If you try to set the from header with the user email address, the message will be blocked or marked as spam by mail servers that will process it.

Here you can find the full documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

You can remove /usr/bin. When not sure about the path of a command you can use env, e.g.:

/usr/bin/env php script.php --attribute hello --import ../world.txt

but not in case of cd, you don't need it.

In any case I'm not sure the above script will work, because the --file attribute is the equivalent of the -f flag, used by the PHP CLI SAPI to define a script or a file to execute, from man php:

--file file
-f file        Parse and execute file

I see that in your tutorial this is used to define a file to import in the script. If you see you cannot get it to work, then change the attribute to something else, like --import and then in the code just replace:

$this->getArg('file')

with:

$this->getArg('import')

then it should work fine.

cereal 1,524 Nearly a Senior Poster Featured Poster

@k_manimuthu

Hi,

the FROM statement is not allowed in the update query, this is reason you get the error. This will work:

UPDATE tb2,tb1 SET tb2.data = tb1.data WHERE tb1.id = tb2.id AND tb2.data IS NULL;

Which is almost the same of your previous query with Reverend Jim fix to match nulls. In alternative you can use a subquery:

UPDATE tb2 SET tb2.data = (SELECT data FROM tb1 WHERE tb1.id = tb2.id) WHERE tb2.data IS NULL;
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, few questions:

  1. which operative system?
  2. can you use PHP or another scripting language?
  3. you have the IP list, nameOFfile.txt is an arbitrary value or defined in the list?
cereal 1,524 Nearly a Senior Poster Featured Poster

In your controller change:

else
{
    $this->load->model('News_model');
    $this->load->view('success');
}

To:

else
{
    $this->load->model('News_model');

    $this->News_model->set_news();  # <- you have to call this

    $this->load->view('success');
}
cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, it's almost fine, just call the method to insert the data, as in my above example. In your case, replace line 33 of your controller with:

$this->load->model('Blogmodel');
$this->Blogmodel->insert_entry();

And it should work fine. Also: use $this->input->post() instead of $_POST, CI will sanitize the data through the input class.

Last: don't use var $abc to declare a property (variable) in a class, the documentation refers to old PHP versions, you should declare the visibility of the property, so:

public $title = '';
public $content = '';
public $date = '';
cereal 1,524 Nearly a Senior Poster Featured Poster

It's easy, create application/models/news_model.php:

<?php 

class News_model extends CI_Model
{
    public $id;
    public $isi;

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

    public function set_news()
    {
        $this->id   = $this->input->post('id');
        $this->isi  = $this->input->post('isi');
        return $this->db->insert('news', $this);
    }

}

Then in the controller load the news model and add the method, in practice change line 33 with this:

$this->load->model('News_model', 'news');
$this->news->set_news();

The insert method will return boolean TRUE on success. You can find more information about models and active record here:

cereal 1,524 Nearly a Senior Poster Featured Poster

The error refers to line 34 or your controller code, it means it does not find the declared view so, create application/views/news/success.php and you solve the problem.

cereal 1,524 Nearly a Senior Poster Featured Poster

@davy what is the output of this?

<?php echo form_open('/CaddLatihan/create'); ?>

It should be:

http://localhost/ci2/CaddLatihan/create

If not, then it can depend on the configuration of the base_url in your /application/config/config.php file:

$config['base_url']

which should be the domain name, or as in your case:

$config['base_url'] = 'http://localhost/ci2/';
cereal 1,524 Nearly a Senior Poster Featured Poster

@iamthwee

hi!

in relation to URL links an absolute path is relative to the domain, so you can migrate to another domain without problems:

<form action="/send/email" method="post">

The above will be the same under http://domain.old/ or http://domain.new/.

In relation to the system directories, instead, you can use the DOCUMENT_ROOT so nothing really changes:

include $_SERVER['DOCUMENT_ROOT'] . '/common/navigation.php';

For backend scripts, which will run on command line, cron & co., I use configuration files because the scrips are outside the document root and will run separated by the Apache/Nginx instance, something like:

<?php

    return array(

        'uploads' => '/srv/path/to/uploads/',

    );

And on script:

<?php

    $paths = require '/config/paths.php';
    echo $paths['uploads'];
cereal 1,524 Nearly a Senior Poster Featured Poster

It happens because you're using a relative path, instead of absolute, i.e. this:

echo form_open('CaddLatihan/create')

instead of an absolute path:

echo form_open('/CaddLatihan/create')

Some additional info you should really read:

cereal 1,524 Nearly a Senior Poster Featured Poster

Load the Form helper into the index() method, at the moment you're loading it only into the create() method:

public function index()
{
    $this->load->helper('form');
    ...
}

Or add the constructor to the controller, so you make it available for all the methods:

public function __construct()
{
    parent::__construct();
    $this->load->helper('form');
}
cereal 1,524 Nearly a Senior Poster Featured Poster

Check also unsplash.com

cereal 1,524 Nearly a Senior Poster Featured Poster

Good! Now, are you loading the database library in your application/config/autoload.php file? For example:

$autoload['libraries'] = array('database', 'session');
cereal 1,524 Nearly a Senior Poster Featured Poster

Then check the contents of the debugger:

print_r($this->email->print_debugger());

You should be able to see the encoding, which is also visible looking at the headers of the received mail, but you should also be able to see if the connection to the SMTP server was done in UTF8 mode, for example:

250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8                 <- this
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, set the default charset for the web server to UTF-8, you can do this by adding this directive into your .htaccess file:

AddDefaultCharset utf-8

And be sure default_charset, in the php.ini file, is set correctly, otherwise set it dinamically:

ini_set('default_charset', 'UTF-8');
cereal 1,524 Nearly a Senior Poster Featured Poster

I don't know if there is a ready PHP solution for this, but if you can install software in your hosting, then use LibreOffice in command line mode:

<?php

    $file = 'something.doc';
    $str  = sprintf("libreoffice --headless --invisible --convert-to pdf %s", $file);
    $cmd  = escapeshellcmd($str);

    exec($cmd);

There are other solutions as unoconv, based on LibreOffice and JodConverter which seems to not be anymore maintained.

cereal 1,524 Nearly a Senior Poster Featured Poster

No worry, it happens! ;)

cereal 1,524 Nearly a Senior Poster Featured Poster

Great, thanks for sharing!

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

regarding the ffmpeg execution in $RF->newname are you returning only the filename or also the path in which this file is located? Is the destination path writable?

Regarding the execution of the controller from CLI, it seems you are autoloading the session library, this will give the kind of warnings and notices you are experiencing, solution is to load the session into each controller or to extend the session library to detect CLI requests:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Session extends CI_Session
{
    public function __construct()
    {
        $CI = get_instance();
        if($CI->input->is_cli_request())
            return;

        parent::__construct();
    }
}

Just save it into application/libraries/MY_Session.php.
Source: http://stackoverflow.com/a/8394485

cereal 1,524 Nearly a Senior Poster Featured Poster

The current stable version is 2.2.1, version 3 is still in development status, it is not stable and probably not even complete, but I'm not sure of this havent tried yet... for more information refer to their documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

So you have a ci controller and a /ci/ directory in which you installed CodeIgniter, when you try to access your ci controller you do something like this:

http://website.tld/ci/ci/

Correct?

I only routes 2 controllers in my routes: ci and caddLatihan. (only ci works)

If it was the .htaccess then your ci controller should not work either, so do not change it. Are you sure caddLatihan is not considered a method of the ci controller?