Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

php script - include_once

Featured Replies

hi, i am trying to include functions from a php review script in my original web layout, to do this i changed my pages from .htlm to .php and i'am using the include_once function to call the script.

 

for some reason when i include the script all code execution halts after it has been callled and focus does not return to the anti-insect.php page so the footer for my site is not shown. im not sure if i need to change a return value for the script or not.

 

this is also preventing me from using multiple include_once to import two or more functions and display them in different area's on my website.

 

this is very frustrating if any one could help me out i would be really happy, i have also included a link to the site that i am testing using the xampp server.

 

http://92.8.199.227/Anti-Insect.php

 

thankyou chris

We would need to see the code of the html and the function file

 

Pat

  • Author

We would need to see the code of the html and the function file

 

Pat

 

thankyou,

 

i have uploaded two files to use as an example but im having this problemb with every include_once / require_once in my site.

 

basically anti-insect.php was originally a .html file,i just changed the file extention and inserted this code to make the script appear where i want it.

 

<header>

 

<div id="Reviews">

<?

$item_id = 1;

global $item_id;

global $item_name;

require_once '/review/my_review.php'; //Works

?>

</div>

 

<footer>

 

this calls my_review.php but i cant get it to return to anti-insect.php to finish executing the footer.

Anti-Insect.php

my_review.php

in the anti insect.php file there is a bit of php code that shouldnt be there

 

</div>

<div id="Footer"></div>
}?>
</div>

 

the }?> shouldnt be there, remove this first and see what happens

 

Pat

 

  • Author

in the anti insect.php file there is a bit of php code that shouldnt be there

 

</div>

<div id="Footer"></div>
}?>
</div>

 

the }?> shouldnt be there, remove this first and see what happens

 

Pat

 

good spot i left that in by mistake, i have removed it and am still having the same issues. :)

  • Author

good spot i left that in by mistake, i have removed it and am still having the same issues. :)

 

any suggestions? This is really annoying me now, i just cant find where the error is and why nothing works after the include_once \ require_once call.

 

thanks

 

Chris

try this

 

<?
//if you're including this file in a directory other than the directory that review_insert.php is in, you must put the full path below or the script won't know where to find it.

//include_once 'review/my_review.php?&item_id=1'; //error
//include_once '/review/my_review.php?&item_id=1'; //error
//include_once ('/review/my_review.php?&item_id=1'); //error

//include_once "/review/my_review.php?&item_id=1";
//include_once "http://92.21.245.69/Anti-Insect.php/review/my_review.php?&item_id=1"; 

$item_id = 1;
global $item_id;
global $item_name;
include_once '/review/my_review.php'; //Works
//include_once ('/review/my_review.php?&item_id=1');

//include_once 'http://92.20.10.211/review/my_review.php?&item_id=1';

//include_once ('/review/my_review.php'); //works
//include_once ('review/my_review.php'); //works
?>

  • Author

try this

 

<?
//if you're including this file in a directory other than the directory that review_insert.php is in, you must put the full path below or the script won't know where to find it.

//include_once 'review/my_review.php?&item_id=1'; //error
//include_once '/review/my_review.php?&item_id=1'; //error
//include_once ('/review/my_review.php?&item_id=1'); //error

//include_once "/review/my_review.php?&item_id=1";
//include_once "http://92.21.245.69/Anti-Insect.php/review/my_review.php?&item_id=1"; 

$item_id = 1;
global $item_id;
global $item_name;
include_once '/review/my_review.php'; //Works
//include_once ('/review/my_review.php?&item_id=1');

//include_once 'http://92.20.10.211/review/my_review.php?&item_id=1';

//include_once ('/review/my_review.php'); //works
//include_once ('review/my_review.php'); //works
?>

 

 

<?

$item_id = 1;

global $item_id;

global $item_name;

include_once '/review/my_review.php';

?>

 

this still dosent work, it executes my_review.php fine but not the footer of anti-insect.php.

this is very strange,could it be any thing to do with the php.ini file?

Yes very strange, can you put this into the css on the anti insect.php page to see if it shows, as it is showing my end.

 

 

#Footer{
background-color: #FFFFFF;
width:990px;
height:27px;
float:left;
}

  • Author

i think this is what you meant,you can now view the source on anti-insect.php and see:

 

#Footer{

background-color: #FFFFFF;

width:990px;

height:27px;

float:left;

}

with the rest of the css.

 

if i had the include_once situated in the header then execution stops before the footer, perhaps in body and i loose more of the content below.

 

thanks

 

Chris

Just a thought ...

 

You have exit; at the end of my_review.php

 

<?php

if (isset($_GET['sort'])) {

BodyFooter();

}

exit;

?>

 

Try removing it.

  • Author

Just a thought ...

 

You have exit; at the end of my_review.php

 

<?php

if (isset($_GET['sort'])) {

BodyFooter();

}

exit;

?>

 

Try removing it.

 

brilliant now it is displaying the footer and will allow me to add another include_once to the same page,

im having agsactly the same issues on this page except this one is also missing the right content and the footer

 

http://92.8.199.227/review-form-page.php?item_id=1

 

review-form-page.php makes an include like :

 

<?

include_once '/review/review_form.php';

?>

 

I have checked the script for the exit function like before but it aint this, i guess this means that it is something in the included script that is failing so the rest of the review-form-page.php code is'nt get executed.

 

 

thank you very much for your help

 

 

Chris

review_form.php

Review-Form-Page.php

have you edited this part of your code

 

if(!is_numeric($item_id)) {
BodyHeader("Invalid item");
echo "The item you are attempting to view is not valid.";
BodyFooter();
exit;
}

 

To this

 

if(!is_numeric($item_id)) {
BodyHeader("Invalid item");
echo "The item you are attempting to view is not valid.";

}

  • Author

ahh wicked i have got it to work now, there was another exit() hidden in the script,it lead me to believe that the include_once was not working properly but it was errors in the script.

this is a great learning curve.

 

thank you for all your help guys.

 

Chris

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.