Jump to content

Recommended Posts

In that case you've misunderstood what require_once() actually does...

Imagine this:

[b]index.php[/b]
[code]<?php
require('connect.php');
require('header.php');
// Rest of the page code here...
?>[/code]

[b]header.php[/b]
[code]<?php
require('connect.php');
// Rest of the page code here...
?>[/code]

You can see here that connect.php is going to be called and loaded twice, once by index and once when header.php is called by index.  A 12k page has just become 24k of bandwidth.  But more importantly, you'll avoid variable redefinitions.

By using require_once('connect.php') it will fetch/retrieve this page and if it comes across a require('connect.php') again, it won't attempt to retrieve it, knowing full well that it has it already.
Link to comment
https://forums.phpfreaks.com/topic/33881-require-once-issues/#findComment-159026
Share on other sites

[quote author=sazzie link=topic=122083.msg503037#msg503037 date=1168605560]
can you suggest a way out?
[/quote]

If you're able to provide some code then we could look into this for you.  Don't forget to surround your code with [nobbc][code]...[/code][/nobbc] tags :)

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/33881-require-once-issues/#findComment-159031
Share on other sites

Here is the code.

This is A.php :
[code]
<?php
[color=red] require_once("B.php");

if( isset($_GET['task']) )
{
$task = $_GET['task'];

switch( $task )
{
case 0:
courses_welcome();
break;
case 1:
t1();
break;
case 2:
t2();
break;
case 3:
t3();
break;
default :
break;
}
}

function courses_welcome()
{
echo "<p>Welcome to our courses</p>";
}

function t1()
{
echo "Testing 1!";
}

function t2()
{
echo "Testing 2!";
}

function t3()
{
echo "Testing 3!";
}[/color]
?>
[/code]

This is B.php :
[code]
<?php
{[color=red]
echo "<div>";
echo "<div class=\"tabArea\">";
echo "<a class=\"tab\" href=\"#\" onClick=\"tab_manager('tabContent', 'A.php?task=0');\"> Welcome </a>";
echo "<a class=\"tab\" href=\"#\" onClick=\"tab_manager('tabContent', 'A.php?task=1');\"> View All Courses </a>";
echo "<a class=\"tab\" href=\"#\" onClick=\"tab_manager('tabContent', 'A.php?task=2');\"> View '07 Courses </a>";
echo "<a class=\"tab\" href=\"#\" onClick=\"tab_manager('tabContent', 'A.php?task=3');\"> Add Courses </a>";
echo "</div>";

echo "<div class=\"tabMain\">";
echo "<div id=\"tabIframeWrapper\">";
echo "<div id=\"tabContent\"></div>";
echo "</div>";
echo "</div>";
}
?>[/color]
[/code]

And the styling just incase :
[code]
div.tabArea {
font-size: 80%;
font-weight: bold;
border: solid 1px blue;
}

a.tab {
  background-color: #f0f0f0;
  border: 1px solid #000000;
  border-bottom-width: 0px;
  padding: 2px 1em 2px 1em;
  position: relative;
  text-decoration: none;
  top: -1px;
  z-index: 100;
}

a.tab, a.tab:visited {
  color: #808080;
}

a.tab:hover {
  background-color: #d0d0d0;
  color: #606060;
}

a.tab.activeTab, a.tab.activeTab:hover, a.tab.activeTab:visited {
background-color: #c0c0c0;
color: #000000;
}

a.tab.activeTab {
z-index: 102;
}

div.tabMain {
background-color: #c0c0c0;
border: 1px solid #000000;
padding: 1em;
position: relative;
z-index: 101;
}

#tabIframeWrapper {
width: 100%;
}

#tabContent {
border: 1px solid green;
padding: 0px 15px 15px 15px;
width: 100%;
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/33881-require-once-issues/#findComment-159112
Share on other sites

I forgot to mention the code is part of a larger Ajax project.

So because I have had to cut out irrelivant code the code provided probably won't duplicate the error I described but it will show the concept of how me code interacts with regards to the required_once call.
Link to comment
https://forums.phpfreaks.com/topic/33881-require-once-issues/#findComment-159134
Share on other sites


Thanks Huggie'. Sorry for the time away - weekend, you see!.

The only other tricks I have up my sleeves right now are :

1. To remove the former rendering of the divs tab and then over write with a new one
    which should sit in the right place - fingers and toes crossed.
2. To render the tabs in a script which calls only once. So the script before the iterative one( A.php ).

Do you know code for 'erasing' and entire div from DOM to help with the first approach? I'm sorry for asking here. I am
sure it's not the right place.
:D
Link to comment
https://forums.phpfreaks.com/topic/33881-require-once-issues/#findComment-160989
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.