cereal 1,524 Nearly a Senior Poster Featured Poster

I am having website error that I still do not know what causes it. In several of my users browsers (firefox), some words in the website content that I build turn into a blue link and also there is a Java ads in it.

Another one, index.html turns into index.css and the user cannot browse the website. Page not found.

It seems that some code was injected into your website. Check the source of the pages and the contents of Javascript and CSS files. Sometimes, these attacks happens through the FTP client, for example:

You're using filezilla, the passwords are saved in clear into an XML file, if a worm or a virus reads the contents of this file, it can connect to the remote web server and inject code, rewrite and delete files.

If your computer is virus free, then it could be your client computer, or a previous developer computer. It's reasonably to think it's not related to your computer, otherwise you would see this problem in all your websites, perform the check anyway. Sometimes the password is not changed for years, a bad practice that expose to these kind of issues.

If you cannot check the logs of the webserver then open a ticket to the hosting and ask them to check. If they confirm the problem comes from FTP, then you must ask for a password change otherwise the virus will overwrite the website again.

So, to repeat:

  1. check the logs
  2. if confirmed it …
cereal 1,524 Nearly a Senior Poster Featured Poster

Check the settings of /etc/apache2/sites-available/default or in apache2.conf and adjust the DocumentRoot to your desired path, then reload apache.

cereal 1,524 Nearly a Senior Poster Featured Poster

If sending through GMail then the From header must be the GMail user, to receive the emails at indonusa.net.id, you have to add the Reply-To header, so:

$from = 'davy.yg1@gmail.com';
$mail->SetFrom($from, $from_name);
$mail->addReplyTo('info@indonusa.net.id', 'Info');
cereal 1,524 Nearly a Senior Poster Featured Poster

Check the ownership and the permissions of the script, by writing the file into /var/www/ you probably used sudo, correct? That gave root:root to the script. Apache needs access to read and execute the file, so you can switch the group to www-data:

sudo chown root:www-data script.php

Then, if your user is part of the www-data group, you can change the permission to allow your edits without using sudo:

sudo chmod 775 script.php

The above is valid for development in localhost, not for production, in that case the rules must be more restrictive.

cereal 1,524 Nearly a Senior Poster Featured Poster

You can use group_concat():

SELECT group_concat(DISTINCT MONTH(postDate) ORDER BY postDate) as months, YEAR(postDate) as year FROM posts GROUP BY year;

with DISTINCT will return unique values, then you can explode the values in the month column and loop them in the sub list:

while($row = $stmt->fetch())
{
    $months = explode(',', $row['months']);
    echo '<li>' . $row['year'];
    echo '<ul class="sub1">';

    foreach($months as $month)
    {
        $slug = 'a-'.$month.'-'.$row['year'];
        $monthName = date("F", mktime(0, 0, 0, $month, 10));

        echo "<li><a href='$slug'>$monthName</a></li>";
    }

    echo '</ul>';
    echo '</li>';

}

Otherwise you can loop the results into an array of years as keys and months as arrays, to create the same of below and then print the result:

$rows[2013] = array(3,5,6);
$rows[2014] = array(2,3,7,8);
cereal 1,524 Nearly a Senior Poster Featured Poster

Apply the default value 0 or just remove $mail->SMTPDebug. I suggest you to read the comments in the source code, it helps a lot to correctly configure the application:

cereal 1,524 Nearly a Senior Poster Featured Poster

Add errorInfo() as suggested in my first post. From there you can see why the query fails.

cereal 1,524 Nearly a Senior Poster Featured Poster

Then try the full path:

require 'C:/xampp/htdocs/phpmailer/PHPMailerAutoload.php';
cereal 1,524 Nearly a Senior Poster Featured Poster

@pritaeas
Whoops, I didn't saw your reply!

With Gmail you can use AUTH LOGIN, but you need an application-specific password before you can go further, read this:

Then generate the password from here:

And then embed this password in your script, as example:

<?php

    require './PHPMailerAutoload.php';

    $mail = new PHPMailer;

    $mail->isSMTP();
    $mail->SMTPDebug = 2;
    $mail->SMTPAuth = TRUE;
    $mail->Host     = 'ssl://smtp.gmail.com:465;tls://smtp.gmail.com:587';
    $mail->Username = '*******@gmail.com';
    $mail->Password = '*******';

    $mail->From = '*******@gmail.com'; # it must be the username
    $mail->FromName = 'Your Name';
    $mail->WordWrap = 50;

    # to
    $mail->addAddress('*******@domain.tld', 'Name and Surname');

    $mail->Subject  = 'Test';
    $mail->Body     = 'Hello World';

    echo ! $mail->send() ? 'Error: ' . $mail->ErrorInfo : 'Success!';

More information about Gmail SMTP here:

pritaeas commented: Thanks. Don't use it often enough to know it has changed. +14
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

the cookie will be available in the next page request, not in the current, so you cannot use setcookie and $_COOKIE in the same instance to get the brand new cookie:

Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE or $HTTP_COOKIE_VARS arrays

In your case:

  1. use directly $user and $row[1]
  2. use prepared statements and avoid the MySQL API: http://php.net/manual/en/mysqlinfo.api.choosing.php

Currently, even by generating the insert query in the next page, a user could alterate the cookie to inject your query, so it is dangerous.

cereal 1,524 Nearly a Senior Poster Featured Poster

Whenever someone sends an email to my websites email address it is piped to a PHP script

Ok, but I hope I can make you understand that when an email message is received by your website, in practice is received by the mail server associated with your domain name.

This does not involve the web server (Apache for example) and neither the PHP engine. So you cannot redirect directly what is received by the mail server to a PHP script.

You can only access the email account and parse the received messages.

Imap, if supported by your mail server, is a protocol that allows to easily access email accounts, otherwise you can use POP3, which is supported also by the Fetch library suggested in the previous post, as example of connection, it could start with two or three arguments:

# for imap
$server = \Fetch\Server('imap.domain.tld', 993);

# for pop3
$server = \Fetch\Server('pop3.domain.tld', 995, 'pop3');

By default the third argument is imap so it can be avoided in the first example. It is just like a connection string to a database. The second argument is the port, and the first is the server path.

If, for example, you want to parse the mails from your GMail account you would do:

<?php

    require './autoload.php';

    $server = new \Fetch\Server('pop.gmail.com', 995, 'pop3');
    $server->setFlag('novalidate-cert');
    $server->setFlag('ssl');

    # set username and password
    $server->setAuthentication('*****@gmail.com', '*******');

    # get 3 messages
    $messages = $server->getMessages(3);

    foreach ($messages as $message)
    {
        echo "Subject: " . $message->getSubject() . PHP_EOL;
        echo …
cereal 1,524 Nearly a Senior Poster Featured Poster

Maybe I didn't understood your initial request: you have a form to send an email, let's say with the mail() function, and you want also to save the input to the database, correct? Or you want to access the inbox of an email account to read the headers and the body of the received messages?

cereal 1,524 Nearly a Senior Poster Featured Poster

In addition, as example you can try imap_rfc822_parse_headers():

<?php

    $header = file_get_contents('email.txt');
    $obj = imap_rfc822_parse_headers($header);

    echo "<pre>";
    print_r($obj);
    echo "</pre>";

Where email.txt is:

Received: from outmail4.bc.edu (136.167.2.48) by BFRANKLIN04.bc.edu
 (192.168.1.34) with Microsoft SMTP Server id 14.2.347.0; Thu, 9 Jan 2014
 09:52:28 -0500
Received: from o1.outreach.nercomp.org (o1.outreach.nercomp.org
 [192.254.118.91])    by krait.bc.edu (8.14.5/8.14.5) with SMTP id s09EqQix012162
    for <bc.person@bc.edu>; Thu, 9 Jan 2014 09:52:27 -0500
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=outreach.nercomp.org;
    h=to:subject:mime-version:from:content-type:content-transfer-encoding;
    s=smtpapi; bh=DvaYBQwmkNJzfT2Ef9kY09h415E=; b=Kg0JHzVv4X8KksSDVc
    0odRBz3RwI7oT1LxX1msR92Z1ilwpcUzGxMA/2Xu74RhzSraWJsjVipE2yuQ1TiM
    lljqwwxRgxTTYxMID3kV1Ql82k/e/G+iYwb+c9VB+43D7u51IYJR9ly/iKS6Pkur
    Cnk1SQEa1esHGuZTTe2yLSb3s=
Received: by mf253.sendgrid.net with SMTP id mf253.19201.52CEB7AA5        Thu,
 09 Jan 2014 14:52:26 +0000 (UTC)
Received: from prod3.jjcbigideas.com (unknown [209.15.240.195])    by mi24 (SG)
 with ESMTP id 143777d7221.2da7.f27c    for <bc.person@bc.edu>; Thu, 09
 Jan 2014 08:52:26 -0600 (CST)
Received: from nercomp by prod3.jjcbigideas.com with local (Exim 4.82)
    (envelope-from <nercomp@nercomp.org>)    id 1W1GyA-0008Uc-2Q    for
 bc.person@bc.edu; Thu, 09 Jan 2014 08:52:26 -0600
To: <bc.person@bc.edu>
Subject: NERCOMP - Security Training and Risk Assessment - Feb 10
MIME-Version: 1.0
From: <events@nercomp.org>
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable
Message-ID: <E1W1GyA-0008Uc-2Q@prod3.jjcbigideas.com>
Date: Thu, 9 Jan 2014 08:52:26 -0600
Return-Path:
 bounces+836485-6dca-bc.person=bc.edu@outreach.nercomp.org

The example header will return an object array:

stdClass Object
(
    [date] => Thu, 9 Jan 2014 08:52:26 -0600
    [Date] => Thu, 9 Jan 2014 08:52:26 -0600
    [subject] => NERCOMP - Security Training and Risk Assessment - Feb 10
    [Subject] => NERCOMP - Security Training and Risk Assessment - Feb 10
    [message_id] => 
    [toaddress] => bc.person@bc.edu
    [to] => Array
        (
            [0] => stdClass Object
                (
                    [mailbox] => bc.person
                    [host] => bc.edu
                )

        )

    [fromaddress] => events@nercomp.org
    [from] => Array
        (
            [0] => stdClass Object
                ( …
cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, the last part of the log explains the problem:

2014-08-24 17:28:33 CLIENT -> SERVER: AUTH NTLM TlRMTVNTUAABAAAABzIAAAAAAAAgAAAAAAAAACAAAAA=
2014-08-24 17:28:38 SMTP -> get_lines(): $data was ""
2014-08-24 17:28:38 SMTP -> get_lines(): $str is "504 5.7.4 Unrecognized authentication type "
2014-08-24 17:28:38 SMTP -> get_lines(): $data is "504 5.7.4 Unrecognized authentication type "
2014-08-24 17:28:38 SERVER -> CLIENT: 504 5.7.4 Unrecognized authentication type
2014-08-24 17:28:38 SMTP ERROR: AUTH NTLM command failed: 504 5.7.4 Unrecognized authentication type
2014-08-24 17:28:38 CLIENT -> SERVER: QUIT
2014-08-24 17:28:38 SMTP -> get_lines(): $data was ""
2014-08-24 17:28:38 SMTP -> get_lines(): $str is "221 2.0.0 Service closing transmission channel "
2014-08-24 17:28:38 SMTP -> get_lines(): $data is "221 2.0.0 Service closing transmission channel "
2014-08-24 17:28:38 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2014-08-24 17:28:38 Connection: closed
2014-08-24 17:28:38 SMTP connect() failed.

The authentication failed because it doesn't recognize the type. The error is defined by the number, which is 504. In one of your previous posts you wrote that you got errors also from the others authentication methods, but these where of the same type or the error code was different?

Anyway to be sure, you must check the documentation of your mail server or ask to the admin.

cereal 1,524 Nearly a Senior Poster Featured Poster

Set:

$mail->SMTPDebug = 4;

It should return a verbose output of the telnet session. If it does not help you to find the error, paste the result here. By the way, you can remove this line:

ini_set("SMTP", "smtp.indonusa.net.id");

It does not affect PHPMailer.

cereal 1,524 Nearly a Senior Poster Featured Poster

But, it generates error.

Which error?

It could be the definition of the columns, for example userrole.userid here is BIGINT but in users.id is INT, the same applies to the other constraint. Then the constraint label must be unique over the database, so if you have another constraint fk_userid into another table, you have to change it.

For more information check the documentation:

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, show an html output of the page, not the PHP source, and the contents of print.css. By the way this:

<link href="print.css" rel="stylesheet">

Should be referenced as print:

<link href="print.css" rel="stylesheet" media="print" />

Unless you're using @media print inside the style.

cereal 1,524 Nearly a Senior Poster Featured Poster

Include the extras directory into phpmailer/. That solves the require_once error. Then retry.

ok, then which authentication type should I use?

If in doubt ask to the mail server admin.

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, this is a problem:

2014-08-21 22:38:07 CLIENT -> SERVER: AUTH LOGIN
2014-08-21 22:38:12 SERVER -> CLIENT: 504 5.7.4 Unrecognized authentication type

You send AUTH LOGIN as authentication type, but there are different methods supported by PHPMailer (line 311 & 274):

PLAIN, LOGIN, NTLM, CRAM-MD5

That can be set by the AuthType property, for example:

$mail->AuthType = 'NTLM';

The default value is LOGIN, check the documentation about your SMTP server.

cereal 1,524 Nearly a Senior Poster Featured Poster

@almostbob

Usually the hosts are 'smtp.server.com' the protocol is taken care of by other declarations, what the instructions say you can and what best practice says you should are way different

You can jump off a 1000 foot cliff, but you probably shouldn't, and you cant do it twice.

Hi, you are correct, but the value refers to the socket opened by the library, which allows the above syntax.

At the end the connection will be executed by line 1332:

if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options))

This is the linked documentation:

/**
 * SMTP hosts.
 * Either a single hostname or multiple semicolon-delimited hostnames.
 * You can also specify a different port
 * for each host by using this format: [hostname:port]
 * (e.g. "smtp1.example.com:25;smtp2.example.com").
 * You can also specify encryption type, for example:
 * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
 * Hosts will be tried in order.
 * @type string
 */
public $Host = 'localhost';

Link:

Then check:

Which is where the string is verified. By using the above you override the default settings.

Maybe I'm wrong, but I think the issue here is given by the port number for the ssl connection. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Read this article:

Standing to the examples, you can try a query like this:

set @num := 0, @type := '';

select site, cat, title, content,
      @num := if(@type = concat(site, cat), @num + 1, 1) as row_number,
      @type := concat(site, cat) as dummy
from news
group by cat, site, title
having row_number <= 3;

Live example: http://sqlfiddle.com/#!9/097fc/10

otengkwaku commented: i realy applicate the effore put into answering my questions thanks +2
cereal 1,524 Nearly a Senior Poster Featured Poster

@Borzoi

at first I thought the same, but it is not correct, check the comments in the source code:

The $mail->Host can be expressed in different ways, even multiple fallback smtp servers:

smtp.domain.tld:25
ssl://smtp.domain.tld:25
ssl://smtp1.domain.tld:465,smtp2.domain.tld:25
cereal 1,524 Nearly a Senior Poster Featured Poster

It's probably generated by:

$mail->Host = "ssl://smtp.indonusa.net.id";

does ssl listen on port 25?

cereal 1,524 Nearly a Senior Poster Featured Poster

Do you have class.smtp.php into the phpmailer directory?

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes, it happens because you are linking directly to the phpmailer class, you have to require the autoload, so instead of:

require_once("phpmailer/class.phpmailer.php");

Do:

require $_SERVER['DOCUMENT_ROOT'] . '/phpmailer/PHPMailerAutoload.php';

AS written in the documentation:

PHPMailer provides an SPL-compatible autoloader, and that is the preferred way of loading the library - just require '/path/to/PHPMailerAutoload.php'; and everything should work.

cereal 1,524 Nearly a Senior Poster Featured Poster

It seems the encoding of your editor change it to UTF8, and replace ‘ and ’ with double quotes.

cereal 1,524 Nearly a Senior Poster Featured Poster

That syntax would not work with the mail() function. By using PHPMailer or SwiftMailer, then you can set username and password as it was suggested to you.

Otherwise you can use fsockopen() as in this example:

And:

Check the error log of the mail server application.

cereal 1,524 Nearly a Senior Poster Featured Poster

No, it's not the same, ini_set affects only the current executed script:

Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

source: http://php.net/manual/en/function.ini-set.php

Using php.ini is like having an included config file common to all the scripts:

<?php

    require '/app/config.php';

You can do a test, open scriptA.php:

<?php

ini_set('SMTP', 'something.tld');
echo ini_get('SMTP');

# stand by for 60 seconds
sleep(60);

And while the above hangs, open scriptB.php from another tab:

<?php

echo ini_get('SMTP') ? ini_get('SMTP') : 'false';

You can verify they will return two different values. Because scriptB will return the setting in the php.ini file or false if this is missing. And if you're using the mail function somewhere else, it could fail.

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

Check the error log of the mail server application. If the mail is not sent or it is rejected the log should have a trace of it.

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes, it is possible, follow these instructions:

Download the installer from: http://php.net/downloads.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Are you sure smtp2 exists? And which mail server is configured under this domain? Xampp doesn't provide a mail server. Also check the DNS records or your domain, I see:

> dig indonusa.net.id ANY

; <<>> DiG 9.8.1-P1 <<>> indonusa.net.id ANY
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10614
;; flags: qr rd ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;indonusa.net.id.       IN  ANY

;; ANSWER SECTION:
indonusa.net.id.    21595   IN  MX  20 mx2.idcloud.biz.
indonusa.net.id.    21595   IN  MX  30 mx3.idcloud.biz.
indonusa.net.id.    21595   IN  MX  10 mx1.idcloud.biz.
indonusa.net.id.    3595    IN  NS  ns1.indonusa.net.id.
indonusa.net.id.    3595    IN  NS  ns2.indonusa.net.id.
indonusa.net.id.    21595   IN  TXT "v=spf1 a mx ptr=all"
indonusa.net.id.    3595    IN  A   202.93.143.59
indonusa.net.id.    3595    IN  SOA ns2.indonusa.net.id. admin.indonusa.net.id. 2014070603 7200 540 604800 86400

;; Query time: 61 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Aug 15 12:03:50 2014
;; MSG SIZE  rcvd: 230

so it seems that your mail servers are mx[1,2,3].idcloud.biz, try to connect to number 3:

telnet mx3.idcloud.biz:25

If it works, then try to configure PHP to connect directly with this server.

cereal 1,524 Nearly a Senior Poster Featured Poster

Try to check the headers and the logs created by your server (both access and error logs) to see if it happens something wrong. Also could you show a sample of the data that will return your CSV?

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, which Chrome version are you using? I've created a little test based on your script, and it seems to works fine for me:

I'm using Chrome 36.0.1985.143.

cereal 1,524 Nearly a Senior Poster Featured Poster

It depends a lot on how you want to save this input, four different columns in this specific order and in a single row, plus $_POST['name']?

If you're going to use prepared statements you can simply submit $_POST['item'] because it is already an array, for example:

    $data = array_merge(array($_POST['name']), $_POST['item']);
    $stmt = $db->prepare("INSERT INTO tablename (name, item1, item2, item3, item4) VALUES(?, ?, ?, ?, ?)");
    $stmt->execute($data);

Pay attention to this:

$data = array_merge(array($_POST['name']), $_POST['item']);

$_POST['name'] is a string, to merge it with the $_POST['item'] needs to be an array, so array($_POST['name']), the above will create:

Array
(
    [0] => Ade Mitchell
    [1] => productA
    [2] => productB
    [3] => productC
    [4] => productD
)

Which ideally cannot be altered. However a user could use an external script to add input fields to the form and add columns to the final array:

Array
(
    [0] => Ade Mitchell
    [1] => productA
    [2] => productB
    [3] => productC
    [4] => productD
    [5] => hello         <-- remotely added by client
)

This will create an error on the insert query that sounds like this:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens'

So what you can do here is to sanitize and limit the amount of input that can be submitted. You have multiple choices, filter_input_array is one of these:

if($_POST)
{
    # filter config
    $config['item'] = array(
            'filter' => FILTER_SANITIZE_STRING,
            'flags'  => …
cereal 1,524 Nearly a Senior Poster Featured Poster

To avoid empty fields, empty spaces and repetitions you can change $values with:

$forSplitProduct = 'productA, productB , productA,';

$values = array_unique(array_map('trim', array_filter(explode(',', $forSplitProduct))));

array_filter will remove the empty value due to the extra comma, array_map is used to execute trim on each value of the array and remove spaces before and after each value, array_unique will remove duplicates, so that the above $forSplitProduct will return only two input fields and not four as in the previous code.

When you receive $_POST['item'] you have to loop it, because it will return an array:

Array
(
    [item] => Array
        (
            [0] => productA
            [1] => productB
        )

    [submit] => send
)

So:

if(is_array($_POST['item']))
{
    foreach($_POST['item'] as $item)
    {
        # execute code:
        echo $item;
    }
}

Test script:

<?php

    $forSplitProduct = 'productA, productB , productA ,';

    if($_POST)
    {
        echo "<pre>";
        print_r($_POST);
        echo "</pre>";
    }

    $values = array_unique(array_map('trim', array_filter(explode(',', $forSplitProduct))));
    $result = array();

    foreach($values as $value)
    {
        $result[] = "<input type='text' name='item[]' value='$value' />";
    }

?>

<form method="post" action="">
    <?php
        echo implode(PHP_EOL."\t", $result);
    ?>

    <input type="submit" name="submit" value="send" />
</form>
cereal 1,524 Nearly a Senior Poster Featured Poster

So this should work, correct?

$forSplitProduct = 'productA,productB';
$values = explode(',', $forSplitProduct);

foreach($values as $value)
{
    echo "<input type='text' name='item[]' value='$value' />";
}

By setting item[] you get an array of results, otherwise you have to set unique names for each input field.

cereal 1,524 Nearly a Senior Poster Featured Poster

Also, if you still want one query to return them all, you could use union in a subquery:

select id, email, tablename from (select u.id, u.email, 'users' as tablename from users as u union select c.id, c.email, 'contacts' as tablename from contacts as c) as sub group by email;

It will return something like this:

+----+-------------------+-----------+
| id | email             | tablename |
+----+-------------------+-----------+
|  2 | contact2@site.tld | contacts  |
|  3 | random3@site.tld  | contacts  |
|  1 | user1@site.tld    | users     |
|  2 | user2@site.tld    | users     |
|  3 | user3@site.tld    | users     |
+----+-------------------+-----------+
5 rows in set (0.00 sec)

Avoiding duplicates between the two tables, and in case one of the two is deleted, the following query will display the result from the other table, so you don't have to keep track of changes:

delete from users where id = 1;

select id, email, tablename from (select u.id, u.email, 'users' as tablename from users as u union select c.id, c.email, 'contacts' as tablename from contacts as c) as sub group by email;

+----+-------------------+-----------+
| id | email             | tablename |
+----+-------------------+-----------+
|  2 | contact2@site.tld | contacts  |
|  3 | random3@site.tld  | contacts  |
|  1 | user1@site.tld    | contacts  | <- note the difference
|  2 | user2@site.tld    | users     |
|  3 | user3@site.tld    | users     |
+----+-------------------+-----------+
5 rows in set (0.00 sec)

Live example: http://sqlfiddle.com/#!9/c8c13/2

But I'm not sure this …

cereal 1,524 Nearly a Senior Poster Featured Poster

@sopu

There are two small errors here:

<img height="100" width="200" src="http://localhost/ci_user/images.'<?php=$row->mco_carimage?>.'

"/>

Remove the single quotes around the PHP statement '<?php ... ?>' and add a slash / to the path, right after the directory name images:

http://localhost/ci_user/images/

The ending code would be:

<img height="100" width="200" src="http://localhost/ci_user/images/<?php echo $row->mco_carimage; ?>" />

This works if mco_carimage will print the filename and the extension of the file. And please, next time open a new thread, bye.

cereal 1,524 Nearly a Senior Poster Featured Poster

$url = filter_var('http://'.$domain_name, FILTER_VALIDATE_URL); and its not returning correct url, it should be $url = filter_var('http://'.$domain_name.$tld, FILTER_VALIDATE_URL);

Yes, you're correct, this morning I was a bit in a hurry but I fixed this in the live example.

and for every domain price is not fixed its randomally changed, because you used $price = mt_rand(3,11); so this is not correct way.

The randomness was just for the example, I agree it's not correct for production :) I tend to generate random data for my test scripts to be sure I'm not pulling data from a cache.

Thanks for the help, I am very glad that you helped me to figured it out. but this problem I figured out myself, :) never mind.

No problem, bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

I'm glad it works fine. You can return the price list as an index => value array, for example:

$prices = array(
    '.com'  => '9.99',
    '.info' => '5.99',
    ...
);

so you can match them into the loop:

foreach($_POST['tld'] as $tld)
{
    $price = money_format('%n', $prices[$tld]);

Note, here I'm using the money_format() function, this requires setlocale(LC_MONETARY, 'en_US.UTF-8'); on the top of the script:

The full script now look like this:

<?php

    setlocale(LC_MONETARY, 'en_US.UTF-8');

    if (!empty($_POST['domain_name']) && !empty($_POST['tld'])){

        # get price list
        $prices = require './generate_prices.php';

        $domain_name = filter_var(trim($_POST['domain_name']), FILTER_SANITIZE_STRING, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
        $responses = array();
        $msg = '';

        foreach($_POST['tld'] as $tld)
        {
            # format the price
            $price  = money_format('%n', $prices[$tld]);
            $url    = filter_var('http://'.$domain_name, FILTER_VALIDATE_URL);

            # stop the loop
            if($url === false)
            {
                $msg .= '<h2>Domain is not valid</h2>';
                break;
            }

            switch($tld)
            {
                # white list
                case '.ac.id':
                case '.biz':
                case '.cc':
                case '.cn':
                case '.co.id':
                case '.co.in':
                case '.com':
                case '.go.id':
                case '.in':
                case '.info':
                case '.mil.id':
                case '.mobi':
                case '.net':
                case '.or.id':
                case '.org':
                case '.pk':
                case '.sch.id':
                case '.tv':
                case '.web.id':
                case '.ws':

                    $domain = $domain_name . $tld;
                    $dns = @dns_get_record($domain, DNS_ALL);

                    # available
                    if(count($dns) == 0) $msg .= "<h2 style='color:green;' >Domain $domain is available for: $price</h2>";

                    # error
                    elseif($dns === false) $msg .= "<h2 style='color:green;' >Error on domain $domain.</h2>";

                    # not available
                    else
                    {
                        $msg .= "<h2 style='color:red;'>Domain <a href='$url'>$domain</a> has taken.</h2>";
                        $responses[$domain] = $dns;
                    }

                    break;
            }
        }
    }
    else if (empty($_POST['domain_name'])) {
        $msg = "<h2 style='color:red;'>Error: Domain name can not be …
cereal 1,524 Nearly a Senior Poster Featured Poster

In the last line there's a missing semi-column:

if(isset($_POST['domain_name'])) echo $msg;

A part that, your code seems fine. Here's a live example:

Just click run for testing.

ultmt.punisher commented: Really helpfull +2
cereal 1,524 Nearly a Senior Poster Featured Poster

Yep, it works fine for me. Change your IF statement:

if (!empty($_POST['domain_name']) && !empty($_POST['suffix'])){

To:

if (!empty($_POST['domain_name']) && !empty($_POST['tld'])){
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, try the W3C validator:

There are some errors like missing tags or inline styles into the table tags, try to fix them using the tips and the suggestions given by the validator.

cereal 1,524 Nearly a Senior Poster Featured Poster

Change your select tag with this:

<select name="tld[]" id="suffix">

Then to avoid duplicates between the selected value and the checkboxes, you can add array_unique() right before the loop:

$_POST['tld'] = array_unique($_POST['tld']);
foreach($_POST['tld'] as $tld)
{

Othwerwise, if you choose, for example, .info from both the input fields the script will receive:

Array
(
    [domain_name] => test
    [tld] => Array
        (
            [0] => .info <- duplicate
            [1] => .org
            [2] => .net
            [3] => .info <- duplicate
        )

    [submit] => submit
)

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,

you can try to generate an array from the checkboxes, change them like this:

<input type="checkbox" id="_org" name="tld[]" value=".org">
<label for="_org">.org</label>

Note that the id attribute of the input tag matches the label for attribute, that way the label becomes clickable, while the name attribute is the array: tld[].

The full example form is this:

<form method="post" action="">
    <input type="text" name="domain_name" />
    <table>
        <tr>
            <td colspan="2">
                <input type="checkbox" id="_org" name="tld[]" value=".org">
                <label for="_org">.org</label>
            </td>
            <td colspan="2">
                <input type="checkbox" id="_net" name="tld[]" value=".net">
                <label for="_net">.net</label>
            </td>
            <td colspan="2">
                <input type="checkbox" id="_biz" name="tld[]" value=".biz">
                <label for="_biz">.biz</label>
            </td>
            <td colspan="2">
                <input type="checkbox" id="_ws" name="tld[]" value=".ws">
                <label for="_ws">.ws</label>
            </td>
            <td colspan="2">
                <input type="checkbox" id="_mobi" name="tld[]" value=".mobi">
                <label for="_mobi">.mobi</label>
            </td>
            <td colspan="2">
                <input type="checkbox" id="_info" name="tld[]" value=".info">
                <label for="_info">.info</label>
            </td>
        </tr>
    </table>
    <input type="submit" name="submit" value="submit" />
</form>

When sending a request it will look like this:

Array
(
    [domain_name] => test
    [tld] => Array
        (
            [0] => .org
            [1] => .net
            [2] => .info
        )

    [submit] => submit
)

Now it's easy to loop the top level domains (tld). In the script you have to use a white-list approach, to avoid arbitrary values, so the script becomes:

$domain_name = trim($_POST['domain_name']);
$responses = array();
$msg = '';

foreach($_POST['tld'] as $tld)
{
    switch($tld)
    {
        # white list
        case '.org':
        case '.net':
        case '.biz':
        case '.ws':
        case '.mobi':
        case '.info':

            $domain = $domain_name . $tld;
            $dns = dns_get_record($domain, DNS_ALL);

            # available
            if(count($dns) == 0) $msg .= "<h2 style='color:green;' >Domain $domain is available.</h2>";

            # error …
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, in practice it happens that because of the fifth argument 2, preg_match() will search the pattern after the second byte, counting from zero. So if your $subject is dedfd, with the offset the function starts to search from dfd.

If, for example, you change the string to abdedfd then the pattern is correctly found. To avoid this problem you can remove the last argument from the preg_match() function and let return the position, so:

$subject = "asddedfd";
$pattern = '/ded/';

preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);

Outputs:

Array
(
    [0] => Array
        (
            [0] => ded
            [1] => 3
        )

)

Where [1] => 3, i.e. $matches[0][1], is the starting position of your searched string, the same result that you can get from strpos().

cereal 1,524 Nearly a Senior Poster Featured Poster

You could use db2_fetch_row() and db2_result(), check the first example in the documentation:

But instead of the loop, that moves the internal pointer to the next row, you can use an IF statement and get only the first row:

if(db2_fetch_row($result4))
{
    $number   = db2_result($result4, 0);
    $alphanum = db2_result($result4, 1);
}

# moving to the second row
db2_next_result($result4);

# repeat the previous IF statement
cereal 1,524 Nearly a Senior Poster Featured Poster

Assign a name attribute to the select tag, a value attribute to each option tag, set the method to the submitting form and then read the matching array, for example, if you set the POST method, then you will have to read $_POST, here's an example:

<form method="post" action="destination.php">
    <select name="color">
        <option value="red">Red</option>
        <option value="green">Green</option>
        <option value="blue">Blue</option>
    </select>

    <input type="submit" name="submit" value="submit" />
</form>

Now the receiving script (destination.php) can do:

<?php

    if($_POST)
    {
        # check if $_POST['color'] is available
        if(array_key_exists('color', $_POST))
        {
            # execute insert query here
            echo $_POST['color'];
        }
    }
cereal 1,524 Nearly a Senior Poster Featured Poster

Hi, it could be the encoding of the server, try to add this to the .htaccess file:

 AddDefaultCharset UTF-8

And read this documentation: http://www.ar-php.org/faq-php-arabic.html#apache