Viewed   31 times

in PHP, how would one return from an included script back to the script where it had been included from?

IE:

1 - main script 2 - application 3 - included

Basically, I want to get back from 3 to 2, return() doesn't work.

Code in 2 - application

$page = "User Manager";
if($permission["13"] !=='1'){
    include("/home/radonsys/public_html/global/error/permerror.php");
    return();
}

 Answers

2

includeme.php:

$x = 5;
return $x;

main.php:

$myX = require 'includeme.php'; 

also gives the same result

This is one of those little-known features of PHP, but it can be kind of nice for setting up really simple config files.

Tuesday, November 15, 2022
5

Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):

$ pecl -d php_suffix=5.6 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.0 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.1 install <package>
$ pecl uninstall -r <package>

The -d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with pecl config-set. The uninstall -r bit does not actually uninstall it (from the docs):

vagrant@homestead:~$ pecl help uninstall
pecl uninstall [options] [channel/]<package> ...
Uninstalls one or more PEAR packages.  More than one package may be
specified at once.  Prefix with channel name to uninstall from a
channel not in your default channel (pecl.php.net)

Options:
  ...
  -r, --register-only
        do not remove files, only register the packages as not installed
  ...

The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).

Monday, December 12, 2022
4

This should work for you.

$array = include('../config/config.php');

$mysql_conn = $array['connections']['mysql'];

$mysqli = new mysqli($mysql_conn['host'], $mysql_conn['username'],
                     $mysql_conn['password'], $mysql_conn['database']);

$query = 'SELECT * FROM action';
$result = $mysqli->query($query);
Monday, December 12, 2022
 
2

You're reading the file line by line, so the line returned will never contain r, n or rn - as those are line separators.

The simplest approach is just to load the whole lot into memory, remove all the line breaks, then write it out:

string text = File.ReadAllText(sourceFileName);
text = text.Replace("r", "").Replace("n", "");
File.WriteAllText(sourceFileName, text);

Of course if you only want to remove carriage returns, just remove the .Replace("n", "") in the above code.

EDIT: Now that we can see your file, there is no XML version 10, which suggests that the document is corrupt before you even get it. You should stop at this point and work backwards towards the source until you can get a valid XML file. There's no point in continuing with what you've currently got.

Monday, August 29, 2022
 
smart_n
 
4

Never used any of those, but they look interesting..

Take a look at Gearman as well.. more overhead in systems like these but you get other cool stuff :) Guess it depends on your needs ..

Friday, November 11, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :