473,387 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

is there a way to initialize php in non-.php files?

n8kindt
221 100+
for every new user our company adds, we give them firstname.lastname@ourdomain.com that forwards to their personal address. as is, this is quite a manual process and i'd rather that this junk is self-automated as there is a great possibility of human error.

currently, the file that holds all the email addresses looks like this...

it starts off like this:
Expand|Select|Wrap|Line Numbers
  1. RECIP=$1
  2. SHELL=/bin/sh
  3. INCLUDERC=.procmailrc.local
and then displays the forwarding data:

Expand|Select|Wrap|Line Numbers
  1. :0
  2. * $RECIP ?? ^^rose.flower=ourdomain.com$
  3. {
  4.     :0
  5.     !rosesemail@charter.net
  6. }
  7.  
  8. :0
  9. * $RECIP ?? ^^laura.person=gurrliegirl.com$
  10. {
  11.     :0
  12.     !laurasemail@pacbell.net
  13. }
  14.  
  15. :0
  16. * $RECIP ?? ^^freddy.jones=gurrliegirl.com$
  17. {
  18.     :0
  19.     !freddysemail@pacbell.net
  20. }
  21.  
as you can see, this is something that i could loop through in php (or any language for that matter--i have no idea what language the above is, however) from a database (mysql). however, the filename has to stay the same as i do not have access to the main config file since this is a hosted server. is there any way to initialize php and then do this looping without a php file extension?? or, can i include a php file into this code somehow? i would rather not edit the file directly b/c that would mean there would still be two spots (my mysql database and this file) with the same exact data.

also, the filename is .procmailrc i'm not sure if that would make a difference in answering this question or not.
Sep 9 '08 #1
10 2017
Atli
5,058 Expert 4TB
Hi.

How is that file executed?
Theoretically the file extension shouldn't matter.

If this is executed via a CLI, the file extension wouldn't matter. Like in Linux, you should be able to do:
Expand|Select|Wrap|Line Numbers
  1. $ php path/to/my/file.ext
And that would execute that file as PHP, no matter what extension.

If it is executed via a HTTP server you would simply have to instruct the server to execute that type of file as PHP, just like it does with .php files.
Sep 9 '08 #2
n8kindt
221 100+
Hi.

How is that file executed?
Theoretically the file extension shouldn't matter.

If this is executed via a CLI, the file extension wouldn't matter. Like in Linux, you should be able to do:
Expand|Select|Wrap|Line Numbers
  1. $ php path/to/my/file.ext
And that would execute that file as PHP, no matter what extension.

If it is executed via a HTTP server you would simply have to instruct the server to execute that type of file as PHP, just like it does with .php files.
i have no idea of finding out exactly how it is executed and i'd really have to do some research on this email program to figure that out. i'm thinking (and hoping) it would be alot quicker to do some trial and error. i'll just assume it is CLI for now...

kind of confused what the $ php path/... does. is it pointing to a file to include and then reading it? if so, i should be able to set up an external php file that generates/formats all the data from my database and then include it in my main file.

for example, i could make a file such as path/to/my/file/db.php like this...
Expand|Select|Wrap|Line Numbers
  1. while ($query_data){
  2. echo $query_data['email'];
  3. //obviously not exact, but you get the idea
  4. }

and then in my .procmailrc do this...

Expand|Select|Wrap|Line Numbers
  1. RECIP=$1
  2. SHELL=/bin/sh
  3. INCLUDERC=.procmailrc.local
  4.  
  5. $ php path/to/my/file/db.php
would that be the same thing as the manual hard coding that exists now?
Sep 10 '08 #3
n8kindt
221 100+
Hi.

How is that file executed?
Theoretically the file extension shouldn't matter.

If this is executed via a CLI, the file extension wouldn't matter. Like in Linux, you should be able to do:
Expand|Select|Wrap|Line Numbers
  1. $ php path/to/my/file.ext
And that would execute that file as PHP, no matter what extension.

If it is executed via a HTTP server you would simply have to instruct the server to execute that type of file as PHP, just like it does with .php files.
oh wow i just re-read that and i obviously missed what you said. i don't have any way to edit the file that executes the file. i only have the supplemental parts to work with. and i could be wrong, but i don't think telling the server to execute it as php would make a difference b/c the server never actually executes the file. i believe this program reads whatever data is in the file and that's it. i'm just wondering if there is a way to include data from a file executed in php into a file such as this or somehow embed php script into this file.
Sep 10 '08 #4
n8kindt
221 100+
let me put it another way. i actually came up with this one from another problem i'm dealing with right now that is very similar. i have a javascript (.js) file that needs the image names/locations generated from a mysql database. i would need to use php to do gather the info from the database. how would i feed the php generated image names/locations into the .js file? my current setup is less than desirable. there has to be some sort of include function in javascript, right? same goes with my other scenario?

of course, i'm merely speculating at this point. i'm probably nowhere near the real procedure to do this.
Sep 12 '08 #5
Atli
5,058 Expert 4TB
Generating JavaScript files with PHP is no problem.

You can create .php file that outputs JavaScript, and then include that file as a .js file in your page HTML.

Like, say:
Expand|Select|Wrap|Line Numbers
  1. # JavaScript.php
  2. <?php 
  3.   // Let the browser know this is supposed to be JavaScript.
  4.   header("Content-Type: text/javascript"); 
  5. ?>
  6. function ShowRandom() {
  7.   alert("<?php echo MD5(mt_rand()); ?>");
  8. }
  9.  
Expand|Select|Wrap|Line Numbers
  1. # Your main HTML file
  2. <html>
  3.   <head>
  4.     <script type="text/javascript" src="JavaScript.php"></script>
  5.   </head>
  6. <body onload="javascript: ShowRandom();">
  7. </body>
  8. </html>
  9.  
Which would show the MD5 hash generated by PHP in a JavaScript alert window.

I don't really know what to do with the other file you were talking about earlier. I don't recognize the language it is using so I can't really say how to use it.

Would it not be possible to simply edit that file using PHP?
You know the syntax, and as I understand it, you are simply trying to automate the process of altering that file. Why not simply alter the file itself, rather than try to dynamically create it each time it is read?
Sep 12 '08 #6
n8kindt
221 100+
Generating JavaScript files with PHP is no problem.

You can create .php file that outputs JavaScript, and then include that file as a .js file in your page HTML.

Like, say:
Expand|Select|Wrap|Line Numbers
  1. # JavaScript.php
  2. <?php 
  3.   // Let the browser know this is supposed to be JavaScript.
  4.   header("Content-Type: text/javascript"); 
  5. ?>
  6. function ShowRandom() {
  7.   alert("<?php echo MD5(mt_rand()); ?>");
  8. }
  9.  
Expand|Select|Wrap|Line Numbers
  1. # Your main HTML file
  2. <html>
  3.   <head>
  4.     <script type="text/javascript" src="JavaScript.php"></script>
  5.   </head>
  6. <body onload="javascript: ShowRandom();">
  7. </body>
  8. </html>
  9.  
Which would show the MD5 hash generated by PHP in a JavaScript alert window.

I don't really know what to do with the other file you were talking about earlier. I don't recognize the language it is using so I can't really say how to use it.

Would it not be possible to simply edit that file using PHP?
You know the syntax, and as I understand it, you are simply trying to automate the process of altering that file. Why not simply alter the file itself, rather than try to dynamically create it each time it is read?
ah, i like that javascript trick. that is slick. much better than having all the messy javascript displayed directly in the page source.

yes, i have considered editing it directly in php. it looks like i may have to settle for that although it is not the most ideal solution. i was hoping that i could allow my users to edit the database in a linked table in microsoft access. so this could get messy if i can't figure out what language this file is in and generate the data from mysql. i'll just have to do some research i guess! i appreciate your replies, Atli. you helped me out a bunch!
Sep 15 '08 #7
pbmods
5,821 Expert 4TB
Heya, n8kindt.

The file you are editing is a procmailrc file.

You can execute shell scripts inside of Procmail "recipes" (for example, calling a PHP script and passing off the email to that script).

Replace all those individual email checks with:

Expand|Select|Wrap|Line Numbers
  1. :0:
  2. | /usr/local/bin/php /path/to/processing/script.php
  3.  
Replace '/usr/local/bin/php' with the actual path to the PHP binary (use `which php` if you don't know) and '/path/to/processing/script.php' with the PHP script that you want to use to connect to the database to process the email.

This will cause your email server to pass every single email to the PHP script, which will then be responsible for final delivery (most likely using the mail() function).

As this represents the extent of my knowledge, I will go ahead and move this thread to the Linux forum so that our resident Linux Experts will be able to help you out should you run into any trouble.
Sep 17 '08 #8
n8kindt
221 100+
Heya, n8kindt.

The file you are editing is a procmailrc file.

You can execute shell scripts inside of Procmail "recipes" (for example, calling a PHP script and passing off the email to that script).

Replace all those individual email checks with:

Expand|Select|Wrap|Line Numbers
  1. :0:
  2. | /usr/local/bin/php /path/to/processing/script.php
  3.  
Replace '/usr/local/bin/php' with the actual path to the PHP binary (use `which php` if you don't know) and '/path/to/processing/script.php' with the PHP script that you want to use to connect to the database to process the email.

This will cause your email server to pass every single email to the PHP script, which will then be responsible for final delivery (most likely using the mail() function).

As this represents the extent of my knowledge, I will go ahead and move this thread to the Linux forum so that our resident Linux Experts will be able to help you out should you run into any trouble.
oh wow, that is great information! thank you so much for all your help! i feel like i'm on the right track now.

alright, well i already foresee one thing that i will need to know. how do i extract all the email information (body, subject, etc) in order to send it to php from there? or is there a way to set it up so that php evaluates the email address and bounces back the required information to procmail?
Sep 17 '08 #9
pbmods
5,821 Expert 4TB
Hm....

That one's tricky. I think Procmail hands it off to PHP and then says, "Ok, have fun. I'm done with you now."

You can test it out by creating a simple PHP script:

Expand|Select|Wrap|Line Numbers
  1. file_put_contents('/some/path/test.txt', print_r($argv, true));
  2.  
Then send an email to an address hosted on your mail server and open the test.txt file that the script created (you might want to change the '/some/path' part). You should get a pretty good idea of what PHP is getting from Procmail.

In terms of handling the email itself, and I could be wrong (it's been known to happen before), but I think you'd need to use mail() to finish sending the email.

I'll go ping the Linux Experts and see if any of them knows any more.
Sep 17 '08 #10
n8kindt
221 100+
Hm....

That one's tricky. I think Procmail hands it off to PHP and then says, "Ok, have fun. I'm done with you now."

You can test it out by creating a simple PHP script:

Expand|Select|Wrap|Line Numbers
  1. file_put_contents('/some/path/test.txt', print_r($argv, true));
  2.  
Then send an email to an address hosted on your mail server and open the test.txt file that the script created (you might want to change the '/some/path' part). You should get a pretty good idea of what PHP is getting from Procmail.

In terms of handling the email itself, and I could be wrong (it's been known to happen before), but I think you'd need to use mail() to finish sending the email.

I'll go ping the Linux Experts and see if any of them knows any more.
thank you for all your help! i will be testing out your suggestion shortly.
Sep 18 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

74
by: Peter | last post by:
Hi, So many times, I have seen compile warning: "you used a char* without initilize it", probably on the code like this: ------------ char* ptr; func(..., ptr); ----------
4
by: qazmlp | last post by:
// Test.C Line-300: namespace Line-301: { Line-302: std::vector<std::string> vecaNS ; Line-303: } The 'SUN Forte 7 C++ Compiler' reports the following warning for the above code:...
4
by: Mark Hannon | last post by:
I am trying to initialize an array only once so it can be seen & used by any functions that need it. As I understand it, if a variable is declared by itself outside of any functions, its scope is...
9
by: www.brook | last post by:
hi, I have a class class A { const int m_a; const int m_b; } m_a can be initialized at the constructor A():m_a(2)
5
by: removeps-generic | last post by:
Hi. I'm using placement new to re-initialize part of an object. Is this OK? struct BaseImp { All& r_all; BaseImp(All& all) : r_all(all) }; struct Calc::Imp : public BaseImp
18
by: toton | last post by:
Hi, In C++ when I initialize an array it, also initializes the class that it contains, which calls the default constructor. However, I want to initialize the array only (i.e reserve the space) and...
15
by: thinktwice | last post by:
char a = { 0 } is it ok?
1
by: BrandonG | last post by:
I am working on a JNI project, the env->NewStringUTF function will only accept a const char as a parameter. The trouble I am having is that within the native method I need to modify the string...
3
by: Bob Altman | last post by:
Hi all, If I have a class that includes an instance of a struct as a member, how do I initialize that struct? I can't find a syntax for the constructor "initializer list" that works. For...
5
by: Timothy Madden | last post by:
Hy static members of non-integral type need to be declared in the class, but defined (and constructed or initialized) outside the class. Like this class SystemName { public:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.