cereal 1,524 Nearly a Senior Poster Featured Poster

Regarding this error:

PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/ro265852/public_html/gd_imagic.php on line 4

Can you show full source of gd_imagic.php?

By the way, from the log you can see the document root:

/home/ro265852/public_html/

So, it's possible that my previous suggestion was wrong, because of the repetition of the public_html/ segment, the correct versions would be:

$src = $_SERVER['DOCUMENT_ROOT'] . '/uploads/photos/' . $filename;
$dst = $_SERVER['DOCUMENT_ROOT'] . '/uploads/thumbs/' . $filename;
cereal 1,524 Nearly a Senior Poster Featured Poster

Hello, sorry for late reply. So, you're almost there, when you define this:

$final_image='/public_html/uploads/photos/'.$filename;

You have to specify the full path, in relation with the document root, you can do it like this:

$final_image = $_SERVER['DOCUMENT_ROOT'] . '/public_html/uploads/photos/' . $filename;

This will add the missing part, apply the same variable to the write context:

$im->writeImage($_SERVER['DOCUMENT_ROOT'] . '/public_html/uploads/thumbs/' . $filename);

If it does not work this can be due to the permission settings of the destination directory, it needs to be writable by the PHP script.

About document root: http://php.net/manual/en/reserved.variables.server.php

Hope it helps, bye! :)

cereal 1,524 Nearly a Senior Poster Featured Poster

Oh, now I understand, no, you don't have to pass the $im object to display the image you have to use the web server path.

In your previous script there is a problem here:

$final_image=$base_url.$path.$newdata;

Where $base_url is probably your url, correct? If you use this Imagick will not be able to read, nor to write the file to the correct destination.

For example if you web server root is /var/www/domain.tld/ and the source directory is uploads/, and the destination path is thumbs/ then the $final_image path should look like:

$final_image = '/var/www/domain.tld/uploads/'.$filename;

After that, by using $im->writeImage() without the first argument you overwrite the original image defined by $im->readImage($final_image), byt thesetting the argument with a new path you write the new image in a new directory, for example:

$im->writeImage('/var/www/domain.tld/thumbs/'.$filename);

Now, you have a query with which you retrieve the image_path column:

select image_path from user_uploads where id=".$p

What is the content of this column? Path and filename? Can you show us some examples?

To display the new image through the browser, instead you have to use the web server path:

echo '<img src="http://www.domain.tld/thumbs/'.$filename.'" />';
cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, the GD library is available also in the PHP linux distribution, however is you still want to use Imagick: which distro are you using: debian, ubuntu, centos? Do you have access to a linux command line (shell/terminal)? Are you sure ImageMagick and the library for PHP are not already installed?

Setup

To check if ImageMagick is there type this in the command line:

identify -version

It should return something like:

Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

Regarding Imagick instead, you can check if the extension is enabled through phpinfo() or by using:

echo extension_loaded('imagick') ? 'true':'false';

if the extension is not enabled, you can check if it does exists by typing this in the linux command line:

locate imagick.so

Or, if locate is missing or not updated, use:

find / -name imagick.so 2> /dev/null

Once you are sure about the existence of the file, just enable it by appending this to the php.ini file:

extension=imagick.so
Install

Debian, Ubuntu and other derived distros from Debian use the apt interface to install software, so if you want to install the extension, type:

sudo apt-get install php5-imagick

As suggested in one of my previouses posts. For other distros, like Centos you have to use the rpm interface:

rpm install php5-imagick

If ImageMagick is missing in both cases you should get a notice and a suggest to continue the process by installing the missing …

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

@Simon your web server is a Windows system, correct? If yes, then the dll pack to download is dependant on the PHP version and the web server configuration, i.e. as Apache is operating. Look at this file name:

php_imagick-3.1.2-5.3-nts-vc9-x86.zip
  1. The first part php_imagick-3.1.2 stands for the Imagick version;
  2. the second part 5.3 stands for PHP version;
  3. the third part nts stands for Non-Thread-Safe against ts for Thread-Safe, this is related to Apache multi-processing modules, if PHP works under Apache with mod_php then the package should match the same setup;
  4. The fourth part vc9 is related to Visual Studio version, it's easy: if using PHP 5.3 and 5.4 it will always be vc9, from PHP 5.5+ it's always vc11;
  5. The last segment x86 is the platform, i.e. a 32bit CPU.

Now, in case you still want to use Imagick, the server must be provided with ImageMagick:

However if your server is not provided with Imagick or ImageMagick, rather then trying to install it by yourself, the easiest solution is to use the GD library which most of the times is embedded in PHP.

cereal 1,524 Nearly a Senior Poster Featured Poster

The $headers variable is not initialized, if you check the error log you should see a notice:

PHP Notice:  Undefined variable: $headers in ...

for this reason the mail() function will fail, to solve the problem you can remove it (since it's an optional argument), set it to NULL or check the examples in the documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes, if you're using Windows follow these instructions:

Under Ubuntu & Co. just type:

sudo apt-get install php5-imagick
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, I suppose SimpleImage is this:

Or a similar version of the above, the error in your code is that you're overwriting the variable $final_image with the new instance of SimpleImage:

$final_image = '/path/to/file.jpg';
$final_image = new SimpleImage(); # <- value overwrite
$final_image->load($final_image); # <- error

So change the above to:

$image = '/path/to/file.jpg';
$final_image = new SimpleImage();
$final_image->load($image);

and it should work fine.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

at the moment this is not a good idea, two or more users could share the same IP address at the same time, if using a proxy or a connection from an office, a library... or in different days: most users use dynamic addresses, so user A today has IP 111.111.111.111, then restarts his router and he gets a new address, while the previous IP will be reassigned to a new user, user B, that will not be able to sign up your service.

Also, if creating a double opt-in sign up system, and sending an email with a confirmation link, you must save both IPs: in some cases a user could submit the form from a desktop and open the confirmation link from a smartphone, submitting two different IP addresses... if one of these is already assigned to another user, with your approach, he will not be able to complete the registration process. Some information here:

To prevent bot spammers implement a captcha:

Preventing multiple accounts, instead, is a lot more difficult.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hello, it's execute, not exectue , so change line 7 to:

$getpic->execute();
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,
check for GD or Imagick libraries, these are both part of PHP:

Also, when saving the images you should optimize them for the web, or at least reduce their quality, read about this topic here:

Anyway don't look only to the file size, but also to the total of the pixels, in particularly read about getimagesize():

A uploader could serve an apparently small file and crash PHP, for example with the below command in ImageMagick you can create a 2.3MB file with 20000 pixels per side, which uncompressed becomes a 3GB file:

convert -size 20000x20000 xc:white -quality 1% test.jpg

If submitted to a PHP script, this will probably crash because of exhausted memory:

For more information, search Daniweb, there are several threads about image resizing with PHP.

SimonIoa commented: thanks +2
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, since you write:

echo form_open("email/send");

The receiving controller should look like:

<?php

class Email extends CI_Controller {

    public function send()
    {
        # code here
    }
}

More information here:

cereal 1,524 Nearly a Senior Poster Featured Poster

You can do:

$ans = array_key_exists('choice', $_POST) && $_POST['choice'] == 'Yes' ? 1 : 0;

so in case of Yes the value of $ans will be 1, in all other cases will be 0. If you need something more specific then use IF/ELSEIF statements:

Best solution, for me, is to use a checkbox, because if this is not checked then it's not sent with the POST request, so you have only to verify if it's received, without dealing with the value:

<p>Have you suffered pain preiviously:</p>
<input type="checkbox" name="choice" value="1"> <label for="choice">Yes</label>

Then in PHP you simply check if you've got the checkbox:

$ans = array_key_exists('choice', $_POST) ? 1 : 0;

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

I've already wrote what is missing. From line 71 to 74, you wrote:

foreach($_POST['choice[]'] as $selected) {
    echo "<p>".$selected ."</p>";
    $qry="insert into diseases (Ans) values ($selected)";
}

Basically you have to repeat the same code you have already used between lines 33 and 38, i.e. you have to prepare and execute the query:

$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "INSERT INTO diseases (Ans) values(?)";
$q   = $pdo->prepare($sql);

$q->execute(array($_POST['pain']));

Database::disconnect();

If you want to use a radio button to choose the value then you do not need an array to save the selected values, because with radio you can choose only one, so you don't even need a loop.

If instead you wanted to perform multiple inserts then the loop would go around $q->execute(array($selected)):

$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "INSERT INTO diseases (Ans) values(?)";
$q   = $pdo->prepare($sql);

foreach($_POST['choice[]'] as $selected)
{
    $q->execute(array($selected));
}

Database::disconnect();

But at that point convert your radio buttons to checkboxes or a multi-select list.

cereal 1,524 Nearly a Senior Poster Featured Poster

If you want to save multiple values then use checkboxes not radio buttons, from a group of radio buttons you must get only one value, assign the same name but different value:

<input type="radio" name="pain" value="1"> Headache
<input type="radio" name="pain" value="2"> Acidity
<input type="radio" name="pain" value="3"> It's lupus

Then in your PHP side simply use $_POST['pain'] to access the selected value.

A part this, in your code I see the query statement at line 73, but I do not see the query execution, so where is that part?

cereal 1,524 Nearly a Senior Poster Featured Poster

Now that we got Problem 2 (as defined by the OP) resolved, on to Problems 1 and 3. Cereal and Mike, still experiencing those issues?

Problems 1 and 3 are solved for me :)

cereal 1,524 Nearly a Senior Poster Featured Poster

Now it seems to work fine, at least for me. I tested the short reply box, new thread & the codemirror link. Thank you Dani!

cereal 1,524 Nearly a Senior Poster Featured Poster

@Dani

Yes, I'm using Ubuntu 14.04, here's my browser version:

Google Chrome   39.0.2171.95 (Official Build) 
Revision    86b48442d063e82f94969f5439badf11c9baeacc-refs/branch-heads/2171@{#461}
OS  Linux 
Blink   537.36 (@186555)
JavaScript  V8 3.29.88.17
Flash   16.0.0.235
User Agent  Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36

Screen resolution is 1366x768.

And yes, I have the same problem at https://www.daniweb.com/dev/codemirror

cereal 1,524 Nearly a Senior Poster Featured Poster

In which script do you set the value for this session index?

Also: do you know that using single quotes will NOT return the value of a variable? If you do:

echo '$banner';

You get $banner, literally. While using double quotes you get the value of the variable, if this is set. If you don't have any special reason to use $ in front of the index name, then avoid it, otherwise you can generate errors.

cereal 1,524 Nearly a Senior Poster Featured Poster

The method result_array() will return an array, or an empty array if the query does not return any results, so:

if(count($events) > 0)
{
    foreach($events as $event_item)
    {
        # ... code here ...
    }
}

else
{
    echo 'No items.';
}
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, I only see two HTML sources. Can you share your PHP code?

cereal 1,524 Nearly a Senior Poster Featured Poster

Without seeing your code it is difficult to answer. Are you using an API to submit these requests?

cereal 1,524 Nearly a Senior Poster Featured Poster

Happy Holidays!

cereal 1,524 Nearly a Senior Poster Featured Poster

In addition.

It does not work because $to exists only in the function scope and since you declare it as function argument $b, you should get PHP notices:

PHP Notice:  Undefined variable: b in line 9
PHP Notice:  Undefined variable: b in line 11

if you want to get the result you can do as suggested previously, basically:

$b = CopyState($a);

Or use references, i.e. function CopyState($from, &$to), documentation says:

If you assign, pass, or return an undefined variable by reference, it will get created.

So the second argument will be created during the execution of the function, example:

<?php

    $a = array(1,2,3,4,5,6,7,8,9);

    function CopyState($from, &$to)
    {
        return $to = $from;
    }

    CopyState($a, $b);

    print_r($b);

Which will return as expected, here's the documentation link:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

@SalmiSoft sorry I just saw your answer!

@Osagie_1

the problem is given by the regular expression in preg_match(), right now you are checking if there is a digit, not for a specific format, so if the expression matches 1 in 100% it goes through.

strtotime() will return false, so date() will execute like this:

$month = date('m', false);
$day   = date('d', false);
$year  = date('Y', false);

Which will return 01 for $month and $day, 1970 for $year, so checkdate() will be:

checkdate('01', '01', '1970')

Which is regular and will return true.

A better check for dates is this:

function validateDate($date, $format = 'Y-m-d H:i:s')
{
    $d = DateTime::createFromFormat($format, $date);
    return $d && $d->format($format) == $date;
}

source: http://php.net/manual/en/function.checkdate.php#113205

cereal 1,524 Nearly a Senior Poster Featured Poster

It happens because the index $_FILES['uploaded'] is not set, this is defined by the attribute name of your input field:

<input type="file" name="uploaded" />

So check if the value is correct. In any case, in your script you should add a check to verify if the $_FILES array is correctly set, for example:

if(array_key_exists('uploaded', $_FILES))
{
    # run code here
}
cereal 1,524 Nearly a Senior Poster Featured Poster

Uh, I think a local server is required so the template can be processed by PHP.

If you're using PHP 5.4+ then you can start the built in server to load the pages. Open a command line an type:

php -S localhost:8000 -t /path/to/website

More information here:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, can you explain your issue? The only problem I see is indentation and the variable $Ok at line 9 which should be $ok, PHP is case sensitive.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi!

I've experienced this kind of issue in past, it was due to a mismatch of mime-types and I fixed by updating the application/config/mimes.php file. But I was trying to upload PDFs and images.

Set the environment constant in the main index.php file to the development stage, set the log_threshold to 4 in the application/config/config.php file and then create a new method in your controller to get a verbose output:

public function verbose_upload()
{
    $config['upload_path'] = "./uploads";
    $config['allowed_types'] = '*';

    $this->load->library('upload', $config);
    $this->upload->do_upload();

    $data['errors'] = $this->upload->display_errors('<p>', '</p>');
    $data['result'] = print_r($this->upload->data(), true);
    $data['files']  = print_r($_FILES, true);
    $data['post']   = print_r($_POST, true);

    $this->load->view('result', $data);
}

And the view (result.php) will look like this:

<!DOCTYPE html>
<html>
<head>
    <title>Verbose Upload</title>
</head>
<body>

<?php 

    if($errors)
    {
        echo "<h3>Errors</h3>";
        echo $errors;
    }

    if($result)
    {
        echo "<h3>Result</h3>";
        print_r("<pre>".$result."</pre>");
    }

    if($files)
    {
        echo "<h3>FILES array</h3>";
        print_r("<pre>".$files."</pre>");
    }

    if($post)
    {
        echo "<h3>POST array</h3>";
        print_r("<pre>".$post."</pre>");
    }

?>

</body>
</html>

Now, no matter what happens you should see what is really sent from the browser. And check the CI logs to see if something is wrong.

If, for some reason, the Upload library is failing then you should get an output from the $_FILES array which is independent from CI, hopefully this output could help us to understand the issue.

cereal 1,524 Nearly a Senior Poster Featured Poster

There are not specific advantages for web pages, but for their components yes: from a performance point of view, serving images (and in general static contents) from different subdomains, will improve the rendering speed of the page. This because browsers limit parallel downloads to two images per domain, so if you have:

domain.tld/images/image001.jpg
domain.tld/images/image002.jpg
domain.tld/images/image003.jpg
domain.tld/images/image004.jpg

Will be downloaded in two rounds, while these:

image001.domain.tld/images/image001.jpg
image001.domain.tld/images/image002.jpg
image002.domain.tld/images/image003.jpg
image002.domain.tld/images/image004.jpg

In one single round. More information:

A part this, I can think to cookies: in past browsers were limiting to 50 to 300 cookies per domain, now the limit changed, but not for smartphones, where the limit is still low, so having multiple subdomains can help you to raise the number of usable cookies.

And there is a lot more if we consider load balancing. It depends a lot in your requirements.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, that's clear, my point is this:

If you can generate that div through PHP, then you don't need to convert it, you have to use the same data source to create a different result, through an image library as GD or Imagick.

If you're working on static HTML, or external pages, then it becomes complex, you could use DOMDocument and then an image library to create the result.

That's why I'm asking those questions.

cereal 1,524 Nearly a Senior Poster Featured Poster

You're welcome! If we are done, please mark the thread solved. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Wait, let's try to simply the task:

  1. you want to write text to an image?
  2. Or you want to extract text from an existing HTML code?
cereal 1,524 Nearly a Senior Poster Featured Poster

It seems all these arrays will have the same size, so you can loop them together, for example:

# read size of one of these arrays
$count = count($_REQUEST['gender']);

# loop
for($i = 0, $e = 1; $i < $count; $i++, $e++)
{
    echo "Student #{$e}: Gender: $gender[$i]    / Shoe-Size: $shoe_size[$i] / Clothing Size: $clothing_size[$i] / Heigth: $growth[$i]<br />";
}
cereal 1,524 Nearly a Senior Poster Featured Poster

You could implement this check directly in your PHP application. For example with rlanvin/php-ip library you can do:

$block = new IPBlock::create('111.111.111.111/24');

if($block->contains($_SERVER['REMOTE_ADDR']))
{
    header('HTTP/1.1 403 Forbidden');
    include $_SERVER['DOCUMENT_ROOT'] . '/error403.html';
    exit;
}

Assuming you're using a switch statement, when the case is mypage you run the IP check:

<?php

    switch($_GET['page'])
    {
        case 'mypage':
            # do check here
            break;

        # other code ...
    }

The same, for rewritten links, can be applied through parse_url(). A part this I don't have other ideas, bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Create $friends like this:

foreach($results as $row)
{
    $friends[$row['id']]['first_name'] = $row['first_name'];
    $friends[$row['id']]['last_name']  = $row['last_name'];
}

So you save the user ID as index key of the array, when you want to compare use array_keys() to generate an array of IDs:

$friend_keys = array_keys($friends);

foreach($friend_keys as $key)
{
    if( ! in_array($key, $membersarray))
    {
        echo $friends[$key]['first_name'] . ' ' . $friends[$key]['last_name'];
    }
}

Or simply:

foreach($friends as $key => $value)
{
    if( ! in_array($key, $membersarray))
    {
        echo $value['first_name'] . ' ' . $value['last_name'];
    }
}
cereal 1,524 Nearly a Senior Poster Featured Poster

IF is part of the core since 2.4, while Require is part of mod_authz_core, which is loaded by default and available since version 2.3, at least in debian & co.

Do you think it would be safe to assume majority of Apache servers (shared hosting etc.) would be using Apache 2.4+ by now?

I don't know, I don't have the numbers but I hope so: 2.4 is stable, while 2.2 is in legacy status and updated only for bug fixes and security patches.

There are a lot of differences between 2.2 and 2.4 but, unless using a specific unsupported module, I would always expect to find the latest stable version.

If you're trying to create a safer approach then use IfModule and IfVersion:

<IfModule mod_version>
    <IfVersion >= 2.4>
        <IfModule mod_authz_core>
            # execute code here
        </If>
    </If>
</If>

Or simply check if mod_authz_core is available.

cereal 1,524 Nearly a Senior Poster Featured Poster

what does [8-9] mean exactly?

This is used to define a range. The mod_rewrite module does not support the CIDR notation, in your case you could write:

RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.$

Or:

RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.[0-9]{1,3}$

By using Apache 2.4 there is another alternative: you can use the IF directive with Require, the matching rule would look like this:

<IF "%{REQUEST_URI} ^/mypage/$">
    Require not ip 111.111.111.0/24
</IF>
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi hi!

If considering only Apache you can try with the Location directive:

<Location /mypage/>
    order deny, allow
    deny from 10.0.0.120
</Location>

The applicable context for this directive is server config or virtual host, it means you cannot apply it into the .htaccess file and after each change you need to reload the server:

If you cannot access Apache configuration files, the other solution is to apply a rule to the rewrite conditions, for example:

RewriteCond %{REMOTE_ADDR} =123\.45\.67\.[8-9]
RewriteRule ^/mypage/ - [F]

Check the documentation below, there are several examples:

Note: in the documentation you will read about Denying Hosts in a Blacklist, this is not a perfect solution because all requests are queued and managed by Apache main process, so if you have a lot of connections, it can become a bottleneck.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

with mysqli_connect_errno() you check if there is an error, if yes then, with the same function, you get the error code, which is an integer, while with mysqli_connect_error() you get a string that describes the error.

The error code allows you to easily create a switch statement to perform specific operations, for example:

switch(mysqli_connect_errno())
{
    # unknown database
    case 1049:
        # mail admin, fallback connection
        break;

    # success
    case 0:
        # do not log, connection is fine
        break;

    default:
        # log normally
}

You can find an error list here:

Now, a MySQL error is composed by three elements:

ERROR 1049 (42000): Unknown database 'db_test'
  • the error code which is an integer
  • the SQLSTATE which is a string of five alphanumeric characters
  • the error message, which is a string describing the error

The MySQLi API does not return the SQLSTATE with the connections errors, you get them only with the queries, for example:

# wrong database
$mysqli = @new mysqli('localhost', 'user', 'pass', 'no_database');

if($mysqli->connect_errno)
{
    echo $mysqli->connect_errno . ': ' . $mysqli->connect_error;
    die();
}

# wrong query, replace `no_table` with `dual`
$mysqli->query("select 'abc' as row from no_table");

if($mysqli->errno)
{
    echo $mysqli->errno . ' ['. $mysqli->sqlstate .']' . ': ' . $mysqli->error;
    die();
}

If still in doubt, the SQLSTATE is a standard to define SQL errors. More info here:

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, as long acadCred.courseCode uses the same format of crse.preReq, your query should work fine. Could you show the table structures and some data?

cereal 1,524 Nearly a Senior Poster Featured Poster

What kind of values are returned by crse.preReq in the sub query: integers, CSV?

If CSV then the IN() clause is not the correct solution, because it can return something like this:

IN('2,3', '11,17,20', '5')

In order to work each value should be separated, not grouped by the row result, as in the previous example:

IN('2','3','11','17','20','5')

If this is the case, then you could use CONCAT_WS() in the subquery and FIND_IN_SET() instead of the IN() clause. For example:

SELECT FIND_IN_SET(21, (SELECT CONCAT_WS(',', 3, 12, 17, 21, 26) FROM dual)) AS result;

+--------+
| result |
+--------+
|      4 |
+--------+

Where 4 stands for the position in the subquery result list: anything different from 0 means a match.

Links:

If this is not the case then, please, provide some extra information about the tables and the result sets.

cereal 1,524 Nearly a Senior Poster Featured Poster

Whoops! There is a little bug in the previous code that prevents correct results when pushing googlemail.com accounts through parseMail() method, fixed by updating the _parts() method:

/**
*   Parse mail, can return email or boolean.
*
*   @param string $str
*   @param boolean $bool
*   @param boolean $strict
*   @return mixed
*/
private function _parts($str, $bool = false, $strict = false)
{
    $isgmail = false;
    $data    = sscanf($str, '%[^@]@%s');
    $compose = array();
    list($local_part, $domain_part) = $data;

    if(in_array($domain_part, $this->domains))
    {
        $local_part = str_replace('.', '', $local_part);
        $local_part = strstr($local_part, '+', true) ? : $local_part;
        $pattern    = '/^([a-zA-Z0-9.]{6,30}+)$/';

        if(preg_match($pattern, $local_part, $match) == 1)
        {
            $isgmail = true;
            $compose = [
                $local_part, '@', $this->default
            ];

            if($bool === true)
                return true;
        }

        else
            return false;
    }

    if($strict === false && $isgmail === false)
    {
        $compose = [
            $local_part, '@', $domain_part
        ];

        if($bool === true)
            return false;
    }

    $compose = array_map('trim', $compose);
    $compose = array_map('mb_strtolower', $compose);

    return implode('', $compose);
}

Previous test:

Array
(
    [0] => user.name@anemail.com
    [1] => username@gmail.com
    [2] => another@gmail.com
    [3] => test@ymail.com
    [4] => this032@googlemail.com    <-- error
    [5] => "valid@test"@email.com
    [6] => awesome@yahoo.com
    [7] => someone@gmail.com
    [8] => anotheruser@gmail.com
    [9] => simple@gmail.com
)

Now:

Array
(
    [0] => user.name@anemail.com
    [1] => username@gmail.com
    [2] => another@gmail.com
    [3] => test@ymail.com
    [4] => this032@gmail.com         <-- correct
    [5] => "valid@test"@email.com
    [6] => awesome@yahoo.com
    [7] => someone@gmail.com
    [8] => anotheruser@gmail.com
    [9] => simple@gmail.com
)
JorgeM commented: Excellent! +12
cereal 1,524 Nearly a Senior Poster Featured Poster

Try video.js: http://www.videojs.com/ it is open source.

cereal 1,524 Nearly a Senior Poster Featured Poster

@pzuurveen sorry, I didn't saw your reply! ;D

@zebnoon1

There are few errors: session_start() must be placed in top of both files. Then, you're submitting the form to session2.php, so the code between lines 14 and 21 of session1.php file will not work: because it runs when you open the page, i.e. before you submit the form.

In order to work: change session2.php to save the value in session and then redirect back to session1.php, in this file check if the session is set and if yes, then display the value. Example:

<?php

session_start();

?>
<!DOCTYPE html>
<html>
<head>
    <title>Session 1</title>
</head>
<body>

    <form action="session2.php" method="post">
        <input type="text" name="text" />
        <input type="submit" name="submit" />
    </form>

    <?php

        # does the session key exists?
        if(array_key_exists('stext', $_SESSION))
        {
            echo $_SESSION['stext'];

            # to delete
            # unset($_SESSION['stext']);
        }

    ?>

</body>
</html>

In session2.php:

<?php

    session_start();

    if(array_key_exists('text', $_POST))
    {
        $_SESSION['stext'] = $_POST['text'];
    }

    # redirect back
    header('Location: ./session1.php');
cereal 1,524 Nearly a Senior Poster Featured Poster

MySQL does not support the varray type, you can use varchar or text to store CSV lists and then use functions like FIND_IN_SET:

cereal 1,524 Nearly a Senior Poster Featured Poster

Problem 2 occurs in both situations for me.

cereal 1,524 Nearly a Senior Poster Featured Poster

Hello!

I'm having few small issues when using Google Chrome on Ubuntu.

Problem 1

It does not seem to indent correctly code snippets, an example here:

Screenshots: Parsed & Plain-Text

It happens only with Google Chrome on Ubuntu, latest version:

Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36

I don't have extensions enabled. I'm not sure this is related to your upgrade.

Problem 2

The second problem, instead, is recent for me and it is not related to code snippets, it is difficult to explain for me, so be patience please ^_^'

When I type in the editor and the cursor reaches the second line, if I try to go to the previous word (which is at the end of the previous line), the cursor jumps at the beginning of the previous line, but if I type something, the text is displayed where the cursor is supposed to be; if, instead, the cursor is at the end of the line and there is a white space, when I try to go back to the previous word, the cursor jumps at the beginning of the current line.

I does not happen, for example, if there is a markdown tag between the two lines.

o_o'

None of these problems occurs on Mozilla Firefox and Opera, latest versions.

cereal 1,524 Nearly a Senior Poster Featured Poster

When using emails as usernames you want them to be unique over your table, but this can be a problem if you consider a GMail account, because of their username policy. They allow:

  • dots
  • digits
  • letters
  • plus addressing text by using the + sign, i.e. orange+juice@gmail.com
  • length between 6 and 30 characters, excluding dots and the appended part

But when resolving the username they do not consider:

  • dots
  • different capitalization
  • plus addressing

So, when you write to:

UserName@gmail.com
u.sername@gmail.com
user.name+forum@gmail.com
.u.s.e.r.n.a.m.e.@gmail.com
u.serName+doh@googlemail.com

You will always match the same account:

username@gmail.com

This class can help to define if the submitted email is a valid GMail address and to get the basic version: when using the parseMail() method it will just validate emails from other providers, so that you can submit an array of emails and get in return all the basics versions of GMail and all the other emails. By submitting an array to the isGmail() method, instead, you will get only an array of valid GMail accounts, in their basic version.

I'm applying lowercase to all the emails, the RFC 2821 allows case sensitive local-parts, but this is discouraged. Some examples:

<?php

    $list = array(
        'user.name@anemail.com',
        'username+acme@gmail.com',
        'email' => 'another@gmail.com',

        array(
            'test@ymail.com',
            'will+fail@gmail.com',
            'this032@googlemail.com',
            '"valid@test"@email.com',
            'Awesome@yahoo.com'
        ),

        'someone+doh@gmail.com',
        'AnotherUser+focus@gmail.com',
        'simple@gmail.com'
    );

    $gm = new GMailParser;

    # testing strings
    var_dump($gm->isGmail('user.name@amail.com'));
    var_dump($gm->isGMail('user.name@gmail.com'));
    /*

    bool(false)
    bool(true)

    */

    var_dump($gm->parseMail('user.name@amail.com'));
    var_dump($gm->parseMail('user.name@gmail.com'));
    /*

    string(19) "user.name@amail.com"
    string(18) "username@gmail.com"

    */


    # testing arrays
    print_r($gm->isGmail($list));
    /*

    Array
    (
        [0] …
diafol commented: Good work c! +15
cereal 1,524 Nearly a Senior Poster Featured Poster

Be aware with this solution: a client could overwrite any index of the $_SESSION array through the $_POST keys. For example, if you set the user id and the status in the session, like this:

$_SESSION['user_id'] = 34;
$_SESSION['is_logged'] = 1;

then a user can submit a form to your script with:

<input type="text" name="user_id" value="34" />
<input type="text" name="is_logged" value="1" />

and gain the access to any desired account without using a password. So, be sure to whitelist all the keys received through the $_POST array and submit to the session array only those allowed by your code:

$allowed = array('othertype', 'issues');

foreach($_POST as $key => $value)
{
    if(in_array($key, $allowed))
    {
        if(is_array($_POST[$key]))
            $_SESSION[$key] = $_POST[$key];

        else
            $_SESSION[$key] = stripslashes(strval($value));
    }
}