digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Ask your hosting what the path to the PHP interpreter is. It probably isn't at /usr/bin/php

Like I mentioned before, it is better to use:

| /usr/bin/php /home/user/public_html/pipe/email_pipe.php >> /home/user/pipe/pipe_error.txt 2>&1

That way you dont need the shebang, and you don't need to make the file /home/user/public_html/pipe/email_pipe.php executable.

Just make sure the path to the interpreter is correct.

You can also test this by running the command from within PHP.

Get the text for a sample email message.

eg:

$email = '
To: user@example.com
From: "example.com" <test@example.com>
Subject: This is a test email
Message-ID: <blablalba@example.com>
X-Priority: 3
X-Mailer: PHPMailer [version 1.72]
MIME-Version: 1.0
Content-Type: text/plain

Hi Jim,

Example text, example text etc.
';

You can then feed this to your php script in the same way the MTA would. I've written a function to do this:

/**
 * Start a child process, and write input to it's STDIN
 * @return Array An array with the format array(stdout=>'', stderr=>'', return=>''). 
 * 
 * stdout - Standard Output from child process
 * stderr - Standard Error from child process
 * return - Return code of child process
 * 
 * @param $cmd String
 * @param $input String[optional]
 */
function childProcess($cmd, $input = '') {
	$pipe_descriptions = array(
	   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
	   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
	   2 => array("pipe", "w") // stderr is a pipe that the child …
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I just noticed that you don't have php tags around your code.

Unlike most other scripting languages, the PHP interpreter requires the <?php tags to consider the code to be PHP.

If you haven't also remove the shebang. Though it should be ignored by the PHP interpreter, it doesn't serve any purpose.

You don't want even a single empty line, or space before your <?php tags.

Also make sure you have the full path to the PHP interpreter correct.

If you use:

| /home/user/public_html/pipe/email_pipe.php >> /home/milano4y/pipe/pipe_error.txt 2>&1

As your command, then make sure the shebang #!/usr/bin/php has the correct path to the PHP interpreter.

Or you can use:

| /usr/bin/php /home/user/public_html/pipe/email_pipe.php >> /home/milano4y/pipe/pipe_error.txt 2>&1

Where /usr/bin/php is the path to teh PHP interpreter.

You don't want the -q flag sent to the PHP interpreter as the previous commands you were using, since you now send errors to the log file.

If you have shell access, you should really just test out the commands you're using - it will give you instant feedback.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

i get the following mail delivery system:

I changed the forward to:
| php -q /home/myuser/public_html/pipe/email_pipe.php >> /pipe/pipe_error.txt 2>&1

But i dont see this file in folder "pipe"

????????

Does the directory /pipe exist in the Root of your server? I'f you're not the root user, you won't be able to create it. Your PHP process won't be running as root, so it can't create it.

You probably want:

/home/myuser/pipe/pipe_error.txt

if you're not root.

If you are root, you have to make sure that folder is writable by the PHP process. ie: use chmod() or chown() as you see fit.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

That is because your column type is set to datetime or timestamp not certain which one actually produces that as I don't use the mysql datetime or timestamp data type.

To store a unix timestamp you just need an INT(10)

It really is best to store a mysql timestamp, or datetime as mentioned:

In your mysql table you should set the type to 'timestamp' and then set the default to 'CURRENT TIMESTAMP'. 

It doesnt really need to be explained. All that is doing is getting the date and time from the server and sticking it in a field. Just remember not to update it when you update the table, that way it will stay the day the user registrated. 
Hope this helps, if you need anything else or i've miss understood dont hesitate to ask. 

Also, if you need more info on timestamp and storing the date, i suggest you consult the manual. It contains some really usefull stuff.

So just create a column of type timestamp. And set the default to 'CURRENT TIMESTAMP'. Can't be any more simple.

This will default to the mysql timezone, however you can change this per connection or globally.
http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html

When you retrieve the date, you can format it directly on mysql or pass it to PHP to do the formatting.

To format it in MySQL:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

To use PHP to format, first convert it to a UNIX_TIMESTAMP.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_unix-timestamp

ie:

"SELECT *, UNIX_TIMESTAMP(Registration_date) …
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

1. "| php -q /home/user/public_html/pipe/email_pipe.php"
2. php PHPMailer()

Are you using CPanel?

Try this for the pipe command:

| php -q /home/user/public_html/pipe/email_pipe.php >> /tmp/pipe_error.txt 2>&1

This redirects input and errors from the process to /tmp/pipe_error.txt

You can replace this with any file path.

Then read the file pipe_error.txt

See what is going wrong.

MTA's won't like it when any output is created by the process it sends the email to. It just see's this as an error.

Also the shebang really doesn't serve any purpose here.

#!/usr/bin/php

It is meant to tell the system which interpreter to use for the script, but in this case you're already using PHP. It really wouldn't matter though since PHP should interpret it as a comment...

If you have shell access to the server (ssh or telnet etc.) you could try executing a file with PHP and see if it works. That would be a start...

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Well you're definitely right. regex is definitely slower when compared to str_replace especially as the length of the string increases. Although return str_replace(' ', '', $str); is not the same as return preg_replace('/\s*/m', ' ', $str); as the regex covers ALL whitespace, newlines tabs etc etc. When i ran your benchmarks on 5.3b1 str_replace did not replace tabs and new lines in the output.

However adding those to an array of replacements in str_replace still drastically spanked the regular expression replacement.

I feel kinda stupid for overlooking to most obvious solution to a few year old thread haha.

Good spotting that one. Yes, it would still be faster with an array of replacements, and even faster if you just did removal of newlines and tabs once outside the function as it doesn't need multiple passes. Only the spaces need multiple passes.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi digital,

Is there any examples to run a cron job under ubuntu 8 because, i can't do it, although i have tried a lot of different examples?

thanks

Are you trying to just input this yourself from the command line or want PHP to do it?

see: http://www.unixgeeks.org/security/newbie/unix/cron-1.html

Basically you need to use: crontab -e

This brings up the default editor, and allows you to edit your user's crontab file.

The syntax:

Now for the more complicated second part of a crontab file.
An entry in cron is made up of a series of fields, much like the /etc/passwd
file is, but in the crontab they are separated by a space. There are normally
seven fields in one entry. The fields are:

minute hour dom month dow user cmd

minute This controls what minute of the hour the command will run on,
and is between '0' and '59'
hour This controls what hour the command will run on, and is specified in
the 24 hour clock, values must be between 0 and 23 (0 is midnight)
dom This is the Day of Month, that you want the command run on, e.g. to
run a command on the 19th of each month, the dom would be 19.
month This is the month a specified command will run on, it may be specified
numerically (0-12), or as the name of the month (e.g. May)
dow This is the …

darkagn commented: Very good explanation of cron +3
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

What is the command you're using in the pipe?

What MTA (mailserver) are you using.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi,

Can i use sleep() for 1 hour? I mean is there any expiry time for it or browser or session so on. Purpose is to send 2000 emails every one hour.

Thanks

For what you're doing the browser should not be in the equation. What you want is to start the PHP script from the command line.

php /path/toscript.php &

You can even use that from within a PHP page.

exec('php /path/to/script.php &');

That way it runs in the background.

Other better options if possible:

Use cron. Write a PHP deamon.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Just to clear things up:

Is there php function to remove the space inside the string? for example:
$abcd="this is a test"
I want to get the string:
$abcd="thisisatest"

How to do that? thanks.

str_replace() will remove *all* occurrence of whitespace.

$str = str_replace(' ', '', $str);

So it solves the problem in the original post.

The post:

Try this:
NOTE: this actually leaves one space between words. If you move the
$newstr = $newstr . substr($s, $i, 1);
after the while loop it will strip all spaces as you wanted.

function StripExtraSpace($s)
{
for($i = 0; $i < strlen($s); $i++)
{
$newstr = $newstr . substr($s, $i, 1);
if(substr($s, $i, 1) == ' ')
while(substr($s, $i + 1, 1) == ' ')
$i++;
}
return $newstr;
}

Offers a solution that removes excess whitespace.

So if you want to turn:

$str = "this     is      a     string     with      excess     whitespace";

into:

"this is a string with excess whitespace";

You could use the StripExtraSpace() function provided above.

For starters, functions in loops should be avoided whenever possible. e.g. for($i = 0; $i < strlen($s); $i++) also, you're doing a lot of extra work here.

I would suggest something like this:

<?php

$sTestString = 'This  is a stringwith    lots of 	odd spaces and tabs		
and some newlines too

lets see if this works.';

$sPattern = '/\s*/m'; 
$sReplace = '';

echo $sTestString . …
nav33n commented: Good post.. +10
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi all. I am having a little trouble trying to get a small script to work. What I am trying to do is create a page to use with DADA mail mailing list software.
I would like this page to search through the DADA mail text file of email address and find if an email specified with a GET variable is in the file.
With one option selected, it would be able to delete it or with another option, if not in the list, add an email to it. I think I can figure out the last one, but I am having difficulties with searching the file. Any suggestions.

Here's what I tried

<?php
$email = $_GET['email'];

$file = "../dada_files/pomona.list";

  $fh = fopen($file, "r");
  $string = fread($fh, filesize($file));
  fclose($fh);

preg_match_all($email, $string, $out);
echo $out[0][0] . ", " . $out[0][1] . "\n";

?>

and I got this error:
Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash in /read_test.php on line 10

If you need the email exactly as it is, you don't need to use regular expressions. Just use stristr() or stripos() which are plain string matches and are much faster. (regular expressions are very very slow in comparison)

If you do use regular expressions such as preg_match() then you need to make sure the first argument is a regular expression.

The regular expression should start and end with a delimiter. The delimiter must not be alpha-numeric or a backslash as mentioned in the error message.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

At the bottom of this thread are two buttons; one says "REPLY W/ QUOTE" and the other says "MULTIQUOTE".

Hoppy

Do a search for "Mark as Solved" on the page and see if you find it.

ie: Ctr+F

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

As much as I can tell it is. The file is being written when output buffering is not on. So I would assume that that means that the directory is OK.

I'm developing locally on a Mac (the folder properties show it not locked and that read & write is allowed) is there any way that could be causing a problem?

If not I'll keep working on it and if I get it I'll make sure to post up the fix.

Thanks again for the help. Really appreciate it.


Richard

Do you sure PHP is displaying errors?

The only thing I can think of is if you have an error occurring in the output buffering part of the code, and it's stopping code execution from moving on to the file writing portion.

Make sure you have error reporting on.

ini_set('error_reporting', E_ALL);
ini_set('display_errors', '1');

See if you get errors.

ps: a shortcut for:

$data = ob_get_contents();
	ob_end_clean();

is

$data = ob_get_clean();
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Thanks to digital-ether, I found this piece of code:

// PHP supports fork/exec/wait but not pipe. However, it does
// support socketpair, which can do everything pipes can as well
// as bidirectional communication. The original recipes have been
// modified here to use socketpair only.

// -----------------------------

// pipe1 - use socketpair and fork so parent can send to child
$sockets = array();
if (!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $sockets)) {
    die(socket_strerror(socket_last_error()));
}
list($reader, $writer) = $sockets;

$pid = pcntl_fork();
if ($pid == -1) {
    die('cannot fork');
} elseif ($pid) {
    socket_close($reader);
    $line = sprintf("Parent Pid %d is sending this\n", getmypid());
    if (!socket_write($writer, $line, strlen($line))) {
        socket_close($writer);
        die(socket_strerror(socket_last_error()));
    }
    socket_close($writer);
    pcntl_waitpid($pid, $status);
} else {
    socket_close($writer);
    $line = socket_read($reader, 1024, PHP_NORMAL_READ);
    printf("Child Pid %d just read this: `%s'\n", getmypid(), rtrim($line));
    socket_close($reader);  // this will happen anyway
    exit(0);
}

This is so simple, a child could do it. To communicate in both directions, you can simply not close the pipe that sends data from the child to the parent until the child is finished (after the pcntl_waitpid).

Thanks again, digital-ether. :) By the way, how do I mark this thread as solved?

Hoppy

Glad that worked for you.

Right at the bottom of the thread, beside the "reply" button you should see the link to mark the thread as solved.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

You're welcome.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I read the URL you provided and especially the user contributed notes that followed. It appears to me that the folks that designed the process control portion of PHP (pcntl) were rank amateurs with little real world experience.

Using pcntl_exec after forking really misses the mark. It has no way to pass anything back to the parent, not even a return code. :(

Take a look at:
http://pleac.sourceforge.net/pleac_php/processmanagementetc.html
http://www.php.net/proc_open
http://www.php.net/socket_create_pair
http://www.php.net/sem

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

My problem is that I have a PHP application that needs to (in Windowsese) multi-task. I am relatively new to PHP and equally new to Linux. I need to know how to pass information from a parent process to a child process and vice versa. If somebody could please provide an example, it would be very much appreciated.

Hoppy

Do you have some code you're currently working with? Could you post this if possible?

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I have a reference to some string. I need to copy (clone) that string.
This is what I tried

$newString = $refToString; //this just copies the ref - no new memory allocated
$newString = clone $refToString; //this creates "__clone method called on non-object" error

If anyone knows how to do this, please help!
Thanks

I believe strings are always copied/cloned on either assignment or modification.

Try:

$str = "joe";
$str2 = $str;  
$str2 .= " blo"; // you have cloned $str to $str2 by modifying $str2

echo $str; // would give you: joe

I'm sure this holds for all PHP versions to date since strings are "basic" types.

Objects are referenced however in PHP5 and above. PHP4 Objects are referenced on assignment. But cloned on modification.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

If you chmod() its is good practice to have the least permissions possible, but still allowing PHP to write to the file/directory. This can be achieved without giving the file a permission of 777, which means anyone on the server will be able to write to that directory (which is very insecure).

Here are some good resources on file permissions on Linux and Apache:
http://www.zzee.com/solutions/linux-permissions.shtml
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch20_:_The_Apache_Web_Server

digital-ether 399 Nearly a Posting Virtuoso Team Colleague
$dir = 'http://www.conway.cz/quizzes/XML';
$quiz_file = getNextFilename_file($dir, 'quiz', 'xml');

Your directory is: http://www.conway.cz/quizzes/XML

This is a URL, not a directory path.

PHP will create a HTTP socket to that URL (if allow_url_fopen is enabled in config).
What you want is for PHP to create a PHP socket to the file system. To do this either supply the absolute path, or relative path to that directory.

eg:

$dir = '/path/to/quizes/XML';

ie: scandir() the function used in getNextFilename() is a file system function, it cannot be used with a HTTP socket.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Edit: Looks like the stored procedure exists across mysql connections.

Try validating each query after you make it in PHP to see if it worked, and get any error messages.
http://www.php.net/mysql_error

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I check the value but it returns this "Resource id #4" instead of the result in PHP.
Also, i dont know where to put delimiter // in stored procedure. Without any adjustment, It works fine in sql command prompt, returns values.

??

It looks like you're viewing the reference to the Mysql connection created when you did mysql_connect() or similar.

Could you post the code.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

that contain Fname and Lname, under the same maximum hrm1id. Help is very much appreciated!

If it is the row that contains the MAX(hrm1id) they you do:

... WHERE hrm1id = MAX(hrm1id) LIMIT 1

Is that what you're looking for?

No need for the UNION, that generates new rows in the result.
You just want to compare two tables side by side and:

SELECT * FROM employee, hrm1_employees

does that.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

i have passed multiple identical id values, and now i want to retrieve those corresponding id values in mysql. how do i retrieve them? the table that the ids were inserted is a join table named hrm1_employees with field names hrmemp1Id, empId, and hrm1Id. the field hrm1Id came from the table hrm1, and empId from table employees, each with ids corresponding to their fields (e.g. empId corresponds to the employees Fname, Lname, etc).

question is how do i retrieve the Fname and Lname and projtitle of the ids.
heres my code:

<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "smportal";


	//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
	//Select Database
mysql_select_db($dbname) or die(mysql_error());
$y=mysql_query("SELECT * FROM hrm1, employee, hrm1_employees WHERE hrm1.hrm1id = hrm1_employees.hrm1id and employee.empId = hrm1_employees.empId");

$display_string = "<table border='2' cellpadding='3'>";
$display_string .= "<tr>";
$display_string .= "<th>Project Title</th>";
$display_string .= "<th>Employees</th>";
    //loop here
	$display_string .= "<td>$row[projTitle]</td>";
		$display_string .= "<tr>";
   while($row = mysql_fetch_array($y))

    {

    //inside while



	$display_string .= "<td>$row[Fname]</td>";
		$display_string .= "</tr>";
	}
	echo $display_string;
	?>

this code is suppose to display the project title once, and the employees Fname multiple times. as the relationship of project to employees is one to many.
can't figure out the code >.< please help

p.s. i am able to pass the correct id properly, i just don't know how to retrieve them, which in this case, the code above is responsible for.

If I follow correctly, the result of the query should give something like:

ProjectTitle, Fname, Lname
-------------------------------
project1, …
fortiz147 commented: thank you very much for your help! very nice professional approach to the problem! +1
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Heres the docs on creating stored procedures:

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

From my tests (on win):

You have to use:

delimiter //

Which will set the delimiter to // instead of the default ;

This will allow you to use ; in your store procedure - it will be treated as a literal.

If you look at the example on the mysql docs:

SELECT COUNT(*) INTO param1 FROM t;

They use "select ... into .. param "

For your purpose, it would be:

SELECT name into name_out FROM table WHERE name= name_in;

In your PHP code you have:

$query = "CALL username($name, @out)";
$run = mysql_query("SELECT @out");

I don't see where the first query is being run, that calls the username procedure.

Should it be:

$query = "CALL username($name, @out)";
$run = mysql_query($query);
$run = mysql_query("SELECT @out");

Also, the reason why you're always getting a result is because mysql will return NULL if you select a variable that does not exist:

eg:

SELECT @test;

Will return:

NULL

The correct way in this case would be to test the value returned, instead of counting the returned rows.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hello,

Is there a way to create new email accounts using php? There must be right? Many sites will give you a mailbox as soon as you register.
How do they do it?

This is for Linux, I don't have any experience with Windows Mail Servers.

Mail servers (MTAs) by default will generally save user mail under their user accounts (shell accounts).

Thus email accounts, are tied to user accounts on the server. So in order to provide mail for a user you have to create an account for them on the server.

Creating user accounts can only be done as root.

PHP running on the server, unfortunately cannot create user accounts directly since the PHP script executes under the webserver user, which won't be root due to security concerns.
You could switch to root from PHP, or invoke a shell script that runs with root privileges, but this has security concerns.

Most the MTA's (http://en.wikipedia.org/wiki/List_of_mail_servers) will allow you to create virtual mail boxes however, that are not tied to user accounts.

Depending on the MTA you use, the way of creating the virtual mail boxes is different, and the setup of the MTA to allow this is different also.

Creating the virtual mail boxes usually means adding to a file that lists the usernames and password hashes, or you can have the users saved in a database.

All you'll need is for PHP to update the virtual …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi all,

Can anyone help me to solve my problem?

I m doing one PHP project in which i maximum used Javascript and Ajax.Now client require that when he close browser session have to automatically cleared means when he open next time that browser he must have to login first.

I tried to use javascript ONUNLOAD event of page but it cant work properly and one problem is that when i click on any other page that event occurs for current page which is also not good.

If you have any idea with php or javascript then please help me.

thanks in advance :-/

How are you keeping the session? Are you using PHP's built in session management or a custom session management?

I believe session cookies (temporary cookies) should be cleared as soon as you close the browser. (those cookies without a date). I've never tested this though, and you could try to see if it actually happens.

Unfortunately, there is no easy way to know when the browser closes, or differentiate between a new page load, and closing the whole browser.

What you could do is on the onunload window event, make a XMLHttpRequest request to the server telling it to close the session in the next 10 seconds or so it there isn't another HTTP request made to it with the same session. If it is a page reload, then right after the XMLHttpRequest the server receives another HTTP request, which is the reload, …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Ok, so then 1 minute would be written as 60 and 1 hour as 3600 and 1 day as 86400?

PHP can measure time in seconds using the time() function.
http://www.php.net/time

or you can use microtime() which is a measure of time in microseconds.
http://www.php.net/manual/en/function.microtime.php

The PHP timestamp is a measure of the number of seconds (or microseconds with microtime) that have elapsed since the Unix Epoch (January 1 1970 00:00:00 GMT). So if you want to work with dates before the Epoch you will have to cater for that in your code. It also cannot measure dates in the future that require more bits then allocated for its datatype - not sure what that date is exactly.

Therefore, normally the PHP time functions are used to get the current date, and make calculations. But if you want to save the resulting date, its better to save it as an actual date if its range may lie outside the limitation of the PHP timestamp.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

The error you're having seems to be the default in PHP when a socket connection attempt times out.

I'd like to suggest anotehr way of going about this:

Test out a socket connection you're trying to make with telnet before trying it with PHP.

I'm not familiar with the socket protocol exchange servers use. I thought they used plain old POP3 and SMTP but it seems the class you're using is trying to make a request for XML over HTTP?

Anway, whatever protocol is being used, try to take a look at the protocol specifications, or just a tutorial on how to test a service using that protocol with telnet to get a basic idea of whats happening on the network level.

That way, you can know what to expect when it comes to coding it with PHP. Using the library may make it more complicated then it is, unless you're already familiar with the protocol.

Basically, once you can telnet into the service, then doing the samewith PHP would be simple.

Here's an example of a simple HTTP Request with telnet:

telnet example.com 80
<enter>
GET /index.html HTTP/1.1
<enter>
HOST: example.com
<enter>
<enter>

The server at example.com with respond with the HTTP resource.

doing that with PHP:

<?php

$fp = fsockopen('example.com', 80);
fwrite($fp, 'GET /index.html HTTP/1.1');
fwrite("\n");
fwrite($fp, 'HOST: example.com');
fwrite("\n");
fwrite("\n");

while($response = fread($fp, 2082)) echo $response;

fclose($fp);

?>

Once you have your simple tests complete, it would …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Is the exchange server on your localhost?
If it isn't then there was no need to configure apache accept ssl.

What I think is happening is the exchange server you're testing on requires SSL and your classes do not support SSL or your PHP build does not support SSL.

Sorry, I don't think that was very clear.

You don't need Apache to accept SSL since you're not making the SSL connection to Apache. The SSL connection is between your PHP script and the Exchange Server.
You'll need your PHP script to talk SSL to the exchange server.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Is the exchange server on your localhost?
If it isn't then there was no need to configure apache accept ssl.

What I think is happening is the exchange server you're testing on requires SSL and your classes do not support SSL or your PHP build does not support SSL.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I made one php project in which we provide facility to create his/her own web site.
Now I wants to add new feature giving different subdomains to the
members' web pages.

Because the number of members is about 120,000, manual configuring is
not the solution.

Let me give you an example.
1) We have domain name such as 'osteopathicwebsites.com'.
2) Someone joined osteopathicwebsites.com with account 'mxi'.
3) He get his own direcory in our Web server such as /mxi/.
(It's url become 'http://www.osteopathicwebsites.com/mxi/' for redirecting his own page.)

4) And I required he should get the subdomain 'mxi.osteopathicwebsites.com' (How can we
implement this???)

If anyone have any any idea then please suggest me.I also try myself by google.

Here is one way to do it:

You need to be able to edit your dns records. Add a wildcard entry for your domain.

Then configure your webserver to serve for each subdomain as well. This depends on the webserver. With apache it would involve creating a virtual host (edit http.conf) and have it serve for your subdomains.

eg:

<VirtualHost *.osteopathicwebsites.com>
ServerAdmin webmaster@osteopathicwebsites.com
DocumentRoot /path/to/osteopathicwebsites.com/root/
ErrorDocument 404 /404.html
ErrorLog /etc/log/osteopathicwebsites.com/error.log
TransferLog /etc/log/osteopathicwebsites.com/access.log
</VirtualHost>

It would actually just mimic what osteopathicwebsites.com has configured, and point to the same document root. So that osteopathicwebsites.com serves all documents for any subdomain.

Then in your php, check for the subdomain, …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Look I can put it in a string, but then it would run you know.

Please can someone look at the code, or give me a usefull hint. Im not a totally newbe.

I'm not too familiar with PHP5 but it would look to me that the only place you can put conditionals in is the function parameters.

I looked at the source at: http://code.google.com/p/mqb/source/browse/trunk/query.php?r=3
Looks like you can't pass empty parameters to a join. You could extend the class however, or modify the sql() method to allow empty parameters.

/**
         * Creates and returns the object as sql string. 
         *
         * @param       int             $as
         * @return      string
         */
        public function sql($as = self::SQL_AS_DEFAULT)
                {
                switch ($this->stats["query-type"])
                        {
                        case self::QUERY_TYPE_SELECT:
                                switch ($as)
                                        {
                                        case self::SQL_AS_DEFAULT:
                                                $join = "";
                                                if (isset($this->token["join"]))
                                                        {
                                                        foreach ($this->token["join"] as $query)
                                                                {
                                                                $join .= " " . $query->sql(self::SQL_AS_JOIN);
                                                                }
                                                        }
                                                return "SELECT" . (isset($this->token["flag"]) ? " " . implode(" ", $this->token["flag"]) : "") . " " . implode(", ", $this->token["select"]) . " FROM " . $this->token["from"] . $join . 
                                                        (isset($this->token["where"]) ? " WHERE " . implode(" AND ", $this->token["where"]) : "") . 
                                                        (isset($this->token["orderby"]) ? " ORDER BY " . implode(", ", $this->token["orderby"]) : "") . 
                                                        (isset($this->token["limit"]) ? " LIMIT " . $this->token["limit"] : "");
                                                break;
                                        case self::SQL_AS_JOIN:
                                                return "LEFT JOIN " . $this->token["from"] . (isset($this->token["where"]) ? " ON (" . implode(" AND ", $this->token["where"]) : "") . ")";
                                                break;
                                        }
                                break;
                        case self::QUERY_TYPE_INSERT:
                        case self::QUERY_TYPE_UPDATE:
                        case self::QUERY_TYPE_DELETE:
                                return false;
                                break;
                        }
                }
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Been lookin at that php mail function today - was able to send a simple email using the examples that are provided

still figuring out how to email results from my query to be sent via email

ive structured a script below - it doesnt work but you can see what i am after

<?php

$host = "localhost"; 
$user = "user_name"; 
$pass = "password"; 
$db = "domains";


mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error());
mysql_select_db($db) or die("ERROR DB:".mysql_error()); 

$query="SELECT domain_name FROM domains WHERE exp_date > NOW()+7 ORDER BY domain_name ASC";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$domain_name=mysql_result($result,$i,"domain_name");
$company_name=mysql_result($result,$i,"company_name");
$simply_account=mysql_result($result,$i,"simply_account");
$notes=mysql_result($result,$i,"notes");
$exp_date=mysql_result($result,$i,"exp_date");



$to      = 'daniel.whiteside@googlemail.com';
$subject = 'Domain renewall reminder';
$message = '


The following domains will expire in 7 days

<BR><BR>

$domain_name - $company_name<BR>

<BR><BR>

Dont forget to renew!<BR><BR>

Domain Team


';
$headers = 'From: oku@sutsurikeru.net' . "\r\n" .
    'Reply-To: oku@sutsurikeru.net' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Not sure where i am going wrong :(

try doing some dumps (var_dump or print_r) of your $message variable in the while loop to see if you're getting what you want.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Well - the query i would use would be very similar to what you posted -

where exp_date > NOW();

Once the domain has expired i dont intrend to delete the record from my database though.

The way i thought it would work would be:

When the domain is 1 week from expiring a query will be run checkin the dates in exp_date to see what domains are going to expire in 7 days

Then if there is a domain(s) about to expire in 7 days it will send an email reminder informing myself - and other members of staff that its goin to expire:

the email format will be something like this

Staff members name(s)

the following domain(s) will expire in 7 days

example.com
example.co.uk
example.net

Else no e-mail is sent until the cron job runs the next day
Or something similar - not to familiar with the mail function though in php

that should work...

PHP mail function.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

The cron will be the easy part - its just structuring the script that i'm finding difficult

Really depends on how you're updating the database. If you're updating just for the case of sending out emails when the domains expire, then you can just delete the rows in the db when you send out an email..

Your query:

SELECT domain_name from domains_table where exp_date > NOW();

Iterate through each row, send email and remove row. Otherwise, you could add another column with the email send timeboolean. So your query would be something like:

SELECT domain_name from domains_table where exp_date > NOW() AND sent_email == FALSE;

Is that what you're trying to do?

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hello everyone,

Well i've just searched the forum to see if my question has been answered prioer to posting, but seem to find the answer.

Well basicly i've created a script to help me monitor and maintain the domain names my company owns (1000's)

I've virtually finished it but i am missing one bit - the auto email's reminding me when a domain will expire - I know you get the reminders from registrars but they only send to myself and others need to know this informaiton eg: Marketing, IT dept and i dont want them to have access to the domain contral panel at the registrar.

So i've been looking up possible ways to generate an automated email - but to no avail.

I have the following fields in my database:

domain_name, company_name, exp_date (Which is the expiry date in 0000-00-00format

So i was wondering if a cron job script can be run daily to check the domains that will expire in the next 7 days. For example if a domain had a exp_date as 2008-05-16 when the script is run on the 2008-05-09 an email will be sent to telling me such a domain is expiring soon.

If any 1 can point me in the right direction, i'd be very greatful

Many thanks

Dan

Which do you have problems with, writing the PHP script or adding the script to cron?

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

can i create dynamic array variable names in php?
my requirement is...

i want a no: of 1-d arrays like $c1[],$c2[],$c3[].

and i need to dynamically create the arrays like this..

for($i=1;$i<$var;$i++)
$c.$i[]=$r;

is there any way to do this?

Use $$. This evaluates the string value of the inner $ as the variable name.

eg:

$name = 'joe';

$$name = 'hello I am joe';

echo $joe; // hello I am joe

Use {} for disambiguation and precedence.

Eg:

for($i=1;$i<$var;$i++)
${$c.$i}[]=$r;

Why do you need to create the variable names dynamically?

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I've worked with fusion charts and I'd recommend it. It has a PHP API on top of the JavaScript API on top of their Flash API.
So you can use either API. The PHP generates Javascript that calls the Flash API that generates the charts.
If you're familiar with JavaScript you can just call the javascript API as it has more flexibility.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

can we go for ms excel for creating charts in php(with mysql) instead of using jpgraph?
please tell me which is the easiest one to use 9between ms excel and jpgraph)?

This really depends on what you need the charts for and how you want to generate them.

If you create them with MS excel you'll need to export them as a format ready for the web. If you can do that then it should be quite simple, yet involve manual exporting and generation of graphs. If you wanted to automate excel to produce the graphs you'd have to use VB Script or C++ or something like that. You could probably use PHP but it wouldn't be the best suited.

If you use Jpgraph it will have the benefits that you can generate graphs dynamically. You can have PHP retrieve the data from a database, flat file, etc. and automatically generate the graphs.

I'd suggest looking at some Flash Charting scripts. They offer interactive charts as opposed to the static images generated by PHP.
You can use PHP to generate the input for the flash charting script. Normally these will take an XML format, which is quite easy to work with.

See:
http://teethgrinder.co.uk/open-flash-chart/
http://www.fusioncharts.com/

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

How can parse an img url as query string to insert an image into a window on another domain?

You can't access the DOM of a window on another domain opened by your domain. This is a restriction that prevents XSS (cross/same domain policy)

If you own the other domain, then you can have PHP display the image by crafting a URL that tells it the image to display and dimensions.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Without rival the most useful javascript debugger/general web development tool is FireBug in combination with Web Developer Toolbar.

Firebug has a very powerful debugger complete with conditional breakpoints and source tracing.

Web Developer Toolbar has a veritable cornucopia of handy tools for web developers.

Firebug wins hands down!

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hello,
I am trying to understand html's <label> attribute. According to http://www.w3.org/TR/html4/interact/forms.html#h-17.9
when I am using a single label for multiple elements I should use the following format: label for = idref [CS]. From what I understand [CS] represents names of the elements that I am labeling. But what is idref? What am I suppose to put there? Would someone kindly post a small example please?

I don't believe labels can be used for multiple FORM elements.

The idref should be the value of the id attribute of the FORM element for which the label is for. The [CS] stands for Case Sensitive. Since IDs are CS also.

So a label can only be for a single element, since you cannot have two IDs of the same value in an XHTML document.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

@JRSofty:

$semname is the name of the folder I want to create. Typical values are "basic0708", "public" or "member". Shouldn't be a problem for the local file system. I mean, the folder is created, just the file cannot be written to it.

@digital-ether:

thanks for that idea. It does work. The properties are set correctly. Just the file is still not created.

Maybe I need a delay between the creation of the folder and the file? I'll try that out.

[EDIT]
I tried to write to that folder when not having created it just before. No chance. Accessing all other folders work perfectly, there are just problems with ones, that I created in PHP.
[/EDIT]

Thats odd, are you sure you don't have error reporting turned off?

Is your PHP running as CGI or Apache module? What's the PHP user?

Can php create files in other directories not created via php's mkdir()?

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

now the problem came to a different point... I changed the charsets for both php file and mysql table from ISO,latin5 to UTF8,UTF8_turkish_ci and then generate xsl file, not an actual excel file anymore though, I just created a file called filename.XSL and wrote some html in it.

That works fine in local as I can manipulate mysql settings as i wish but in server it's a bit tricky, mysql collation is set to utf8_general_ci and when i generate the file, chars again look weird but when i check the source of the file, there chars are fine. now i'm very confused!!!

Make sure your browser sees the encoding correctly. In the XSL file you generate, make sure the HTTP Header "Content-Type" is being set to "text/xsl; charset=utf-8". (I'm not sure what the XSL mimetype is).

If you use Firefox as your browser, install the firebug extension and view the HTTP Headers.

Its fuzzy how browsers choose the encoding, but usually the HTTP Content Type header overrides the others.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi,

I try to take data from mysql and insert into xls. I achieve that but I cannot sort out the char problem. Turkish characters are displayed in a weird shape in the file but everything seems fine when i display them in a web page.

I tried ISO-8859-9(which is turkish) then tried UTF-8 for both php pages and mysql but still there's the problem.

What happens is, if i send the data with $_POST it writes into file as it is but once i input the data to mysql and return it to the file there i get the problem.

Any ideas how to sort it out?

It sounds like the encoding is being mangled by MySQL. Masking the special characters as suggested is not a bad idea, but probably not the best solution. This would also be similar to converting the characters to html entity equivalents, which would be a bit faster since you could use the native PHP funciton htmlspecialchars(). This would be ready for display in XML languages, such as xHTML without having to convert back.

What charset is your data being saved as in the database? What is the database field/column type?

Just make sure you save the characters in the database as the same character encoding you receive them as, or convert them to the database field encoding. That way the database wont mangle them.

You can then convert the data to any charset, encoding you need for display.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi everyone,

I'm now fiddling over a week to fix a problem on my linux-webserver.

I have the following code:

...
$bool=mkdir(trim($semname), 0777, TRUE);
//chmod(trim($semname),0777);
$f2=fopen(trim($semname)."/index.php","w");
...

it works perfectly when working on my home server under windows but as soon as loaded up on my linux-webserver it just creates a folder with permission 755. The permission of the root-folder is also set to 0777, but no index-file is created.

What's wrong? I can't even find anything on php.net.

Thanks very much indeed
Simon

Take a look at the umask() function.

In order to create a folder with 0777 permissions you need to first set the umask to 0000, then do the mkdir(), then you can set it back to its original value.

eg:

$orig = umask(0000);
$bool=mkdir(trim($semname), 0777, TRUE);
//chmod(trim($semname),0777);
$f2=fopen(trim($semname)."/index.php","w");

umask($orig);
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Of course, running a while loop till I get what I want or picking up elements based on their tag name is how I normally do things. I just wanted to let the OP know where he had made a mistake.

Was aiming that at OP and the DOM universe in general.. :)

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

You have got to realize that when we talk of XML, the whitespaces in your document matter and they get counted as a "#text" node. Assuming that xmlObj has the reference of the root node of the document, something like alert(xmlObj.childNodes[1].firstChild.nodeValue); should do the trick.

Here:


Assuming the XML file is:

<?xml version="1.0" standalone="yes"?>
<code>
    <name>sree</name>
</code>

I'd suggest making sure you don't have any whitespace in your XML. That way, you don't need to have to cater for text nodes where you don't want them.

It may also be better to traverse the XML nodes, instead of selecting 'blindly', unless you are 100% sure the XML structure will not change.

eg: to get first non-text child

function getFirstChildTag(Node) {
var len = Node.childNodes.length;
for (var i = 0; i < len; i++)
   if (Node.childNodes[i].nodeName != '#text') return Node.childNodes[i];
}
master.value = getFirstChildTag(xmlObj).firstChild.nodeValue;

or use DOM methods such as getElementsByTagName() so that you're sure you're getting only what you want.

master.value=xmlObj.getElementsByTagName('name')[0].firstChild.nodeValue

If selecting 'blindly', test for the existence of each parent node first, then fallback if it doesn't exist.

eg:

if (xmlObj && xmlObj.childNodes ... etc
else ... etc
digital-ether 399 Nearly a Posting Virtuoso Team Colleague