Jump to content

Recommended Posts

Hi

 

Newbie here - I have written a fairly large php script that handles the data management of a large database.  I would like to be able to split the php file into smaller more focused scripts that just do the task of one operation - say manage users, another to manage the contractors in the db, another to manage the parts in the db, and so on.

 

How do I get my main/index.php to call another .php file and pass control to that called .php file?  I want control to pass to the called .php file and "close" the calling .php file.  Hope that makes sense.

Binder.

Link to comment
https://forums.phpfreaks.com/topic/164949-solved-pass-control-to-another-php-file/
Share on other sites

Hi madtechie

 

I'm building my system so that once I have the user login and the user has supplied a valid id and password, they will get passed to menu.  The user would then make a selection from the menu - say manage items.  I'm thinking (and this is coming from a non-web world, I'm an old vba programmer ;D) the menu .php script should end/close and the manage items .php script should start/open.  IE - instead of having one huge .php file that tries to control all the different options and menu choices, break it into smaller .php files that do smaller jobs.  Each time a .php files closes it would pass certain info - user name, session id and such to the new opened .php file.

 

Make sense - or am I going about this the wrong way?  Is there a better way to break control in a large system down?

 

Binder

 

okay a simple way to think of if is like actions

 

for example heres my main page (with menu)

<a href="?action=home">home</a><br />
<a href="?action=contact">contact</a><br />
<?php
switch($_GET['action'])
{
case "home":
	include "home.php";
break;
case "contact":
	include "contact.php";
break;
}
?>

 

and heres my pages

<?php
echo "contect page";
?>

 

<?php
echo "home page";
?>

 

Now thats kinda basic..

you could also create a file with functions

ie

<?php
function getUserList()
{
//..code
return array();
}

function getUserDetails($UserID)
{
//..code
return array();
}
?>

and include that into another file to use the functions

That helps a lot thanks.

 

So when a .php is included, the main script is still running?  Correct?

 

What does the header("Location: xxx") command do and how is it different from an include?

 

Sorry to be a pest - thanks in advance for your time.

Binder.

That helps a lot thanks.

 

So when a .php is included, the main script is still running?  Correct?

correct, its like you copied and pasted that code into that place, but if you create function you can call them when needed,

 

breaking your large script into smaller functions should help.. then you could put all the database functions into database.php and all the display functions into display.php,

once you get used to that then Look at OOP

 

 

What does the header("Location: xxx") command do and how is it different from an include?

 

Sorry to be a pest - thanks in advance for your time.

Binder.

 

Okay header()  controls the Page header (who would of guessed) the  Location: prefix tell the browser to goto another page.

its basically a redirect.. but unlike javascript or metatags you can't have anything displayed on the page

Thanks!  I think I understand much better now and will go and try out some code and see my results.  I very much appreciate your help.

 

I had been looking at OOP php but figured I'd tackle php from a procedural viewpoint as that's my background.  I'll give that a shot soon.

 

Thanks again

Binder.

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.