Jump to content

calling a php script from within a php script


jeffery1493

Recommended Posts

Hi all,

Does anyone know how to call a php script within a php script.  I have been racking my brain for hours and can't find the answer to this anywhere.

I have a freeware php script that presents a user with a pay screen, and I only want it to run if a certain condition is met in the original php script.
Something that logic would assume would work like the example below.

On my fourth hour of web searching, thanks for any advice

JEFFERY1493




//
// Here check if payments are enabled. If enabled, send user to the Payment screen for that member.
//

if( ( $mode == 'newtopic' ) && $is_auth['payment_group_member'] )
{

//call http://www.website.com/phpbb/payment_deposit.php, and pass it a couple variables. After it closes, return.
exec("payment_deposit" . $phpEx);

}
Link to comment
Share on other sites

include_once didn't work in this case, but the echo line did.    With include_once calling it flat it simply hangs at a blank screen with the address showing.

I've been struggling with 'includes' for awhile.  The payment routine was written by someone else and is fairly complicated with nested templates and such.  I just want to invoke the program and hopefully pass a variable to it telling it which customer is paying.

I also was wrestling with trying to port it all into a function inside the original php, but it is apparently out of my mental capacity to accomplish.......I ended up scrapping the attempt and trying for an exec approach.

The payment program being called is kind of like a giant building made of sahran wrap and duct tape.......start moving it and it collapses quickly into ruin..........


I imagine you could pass arguments to it using the html header? 
Link to comment
Share on other sites

[quote author=jeffery1493 link=topic=121599.msg500368#msg500368 date=1168315526]
Genius!!!


I tried the first (echo line) and it works great, I haven't attempted the 2nd yet.

Do you know how you would pass any variables on that line (like tell the called program it who the customer is)


[/quote]

pass them in the url as variables such that

[code]echo"<script>location.href='payment_deposit." .$phpEx."?myvar=" . $phpVAR . "';</script>";[/code]
and then call them on the next page as $_GET['myVar'];  see how that works?

or

pass them as $_SESSION['myVar'];  and reference on corresponding page as $_SESSION['myVar'];  making sure before creating on the first page and before calling on the second page that you have session_start(); after your <?php tag

One more thing..have you studied php at or or done any reading at all?
Link to comment
Share on other sites

to use a var created outside a function inside a function you must make it global

I am a little fuzzy about the whole global thing and have managed to make it work in my scripts, but I do know that the following is true

[code]
$x=1;  //sets $x to 1
$x++;  //increments $x by 1  so it equals 2

function somefunction(){
$x=5;
}

echo $x [/code]

this will output 2

because a var inside the function is not changed outside and vice versa.


Once thing you can do is simply do

[code]function showpaymentscreen(){

include('big script name here');

}[/code]

I think that would work?? Any other ideas on this one folks?

Is the orginal code 1 page? If so post here and maybe we can help wrap it inside a function.. If not, let us know and maybe we can do something else for ya
Link to comment
Share on other sites

I've gone with his original path as yucky as it may seem compared to the more efficient and effective route you have given chron..and i think he has gone with it as well...perhpas when he reads alitte int he future and learns alittle more about OOP he can go the better way..
Link to comment
Share on other sites

Thanks you guys have been alot of help.

I have a UNIX background and SQL, and have done Perl programming.    But I have no PHP training besides Google, a couple HTML books and a recent subscription to a bunch of grouchy people at phpBB.com.   

Yes, in my 15 yrs or so as a computer tech, I've found myself eternally a clueless fool surrounded by people who are old hat at a subject I have never or hardly ever seen before.   
If you're lucky (as a temporary contractor), you can survive the politics, keep out of the way of the people with real jobs and survive until you're laid off and on to the next computer language.

In this case however I'm trying to set up a website on my own.  Thank god for unemployment insurance in the Era of the H-1 License...............
Link to comment
Share on other sites

C is pretty cool stuff.  Informix is even better.
PHP books on order.  I'd like to stay with one language long enough to get good at it, if people would only consent to keep paying me.  :P
I can't comprehend someone who has been employed working on the same language or system for 5, 10 years or more.........let alone people working on the same database system all that time, or getting to set their own system up administrate it. 
Lucky, indeed.

(thanks & out)
Link to comment
Share on other sites

Read up and study...

I have touched no other programming language before PHP and I am not an expert, but I can manage

If I can pick up on this stuff with having no programming experience, you can most certainly do so with a perl background

You will not find any grouchy people around here. This is the most helpful forum I have ever seen. I came here with a question and now I have 100 posts (WHOO HOO I HIT FORUM HELPER TONIGHT)

These folks are some amazing people and are astonishingly patient with newbies. They are even patient with the occasional person who don't want to learn, but be told how to do it (I am not referring to you just so I am clear.)

So good luck and stick around, you could learn a thing or 2  ;D

Regards,
Nate
Link to comment
Share on other sites

I actually had one of my posts locked there so I couldn't reply anymore.  ;)
They're smart but hair-trigger over there.

I'ts a pretty safe bet if I post a question I've spent at least two hours struggling on the net trying to find it.  As Regis Feldman says, "It's always easy when you know the answer".


Here folks is my donation to the site:

PHP Tutorials:

http://www.tizag.com/phpT/
http://us2.php.net/manual/en/index.php
http://www.freewebmasterhelp.com/tutorials/php


PHP and BB Hacks:

http://www.mushware.com/hacks_list.php
http://www.phpbbhacks.com/categories.php


PHP oddities:

moveover mouse:  http://www.javascriptkit.com/script/script2/soundlink.shtml
automated script:  http://www.phpfreaks.com/forums/index.php/topic,121574.0.html
function reference: http://www.php.net/manual/en/function.number-format.php


HTML tips:

HTML reference:          http://www.blooberry.com/indexdot/html/index.html
Quick Color Chart:        http://www.kanzaki.com/docs/colortable-t.html
Freeware web designer:  http://nvudev.com/guide/1.0PR/ugs01.htm
(As good as FrontPage, as far as I'm concerned)  ;)


Link to comment
Share on other sites

[quote]I'ts a pretty safe bet if I post a question I've spent at least two hours struggling on the net trying to find it.  As Regis Feldman says, "It's always easy when you know the answer".[/quote]

Then you should have no trouble finding someone(or several people) willing to help. This place is loaded with helpful people. They have no problem trying to help someone understand a concept better if that person is willing to learn. I even saw one person (can't remember who) post about 3-4 pages of code for someone else. I was amazed that they simply did all the work for them.

I have also seen some people flat told "We are not going to do the work for you, research and learn"

Good luck to ya in your php journeys. If you want, shoot me an email and I can hook you up with some pretty good PHP resources. My email is in my profile.

Nate
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.