Avatar billede dexxa Nybegynder
28. maj 2001 - 20:20 Der er 15 kommentarer og
1 løsning

Include af PHP gennem javascript!!

Hej jeg har et dokument på min webserver:
www.domæne.dk/inkluder.php

Det har nogle If og else variabler, og jeg havde i starten tænkt mig bare at uploade det på de sider det skal inkluderes på, men da de ligger på ASP Servere uden PHP understøttelse virker det jo ikke så godt.

Indholdet af inkluder.php:
Ps. dette er ikke det præsise der i filen inkluder.php, i den rigtige version er der også en connection til en MySQL og lidt andet. Men en grundlæggende opbygning af filen..
- - - - - - - - - - - - - - - - -

<?
if($sog == \"reseller\")
{
print(\"Reseller løsninger bla bla..\");
}
elseif($sog == \"hosting\")
{
print(\"Hosting løsninger bla bla..\");
}
else
{
print(\"Du søgte efter noget andet\");
}
?>
Altså overstående ligger på domæne.dk/inkluder.php


På domæne2.dk som ligger på en helt anden webserver, er der en masse brugere der hver dag går ind od udfylder en form med navn \'sog\' og nede i bunden af deres side skal der så includes overstående.. Dvs. Domæne2.dk skal kunne indsætte et stykke kode som så henter domæne1.dk/inkluder.php og viser det som var det en del af domæne2.dk!

Jeg ved det kan lade sig gøre ved at lave noget Javascript-print eller hvad det hedder

Aner bare ikke hvordan..
Håber på noget hurtigt hjælp
På fordhånd tak.

DeXXa
Avatar billede bigo Nybegynder
28. maj 2001 - 20:46 #1
Avatar billede bigo Nybegynder
28. maj 2001 - 20:47 #2
må vist være det..
Avatar billede dexxa Nybegynder
28. maj 2001 - 20:48 #3
du kan da ikke blive include bare midt i en HTML dokument ?
Avatar billede bigo Nybegynder
28. maj 2001 - 20:51 #4
narj..
<?php
include (\"http://someserver/file.php?varone=1&vartwo=2\");
?>
Avatar billede bigo Nybegynder
28. maj 2001 - 20:52 #5
så den nok mere bliver:

<?php
include (\"http://domæne1.dk/inkluder.php\");
?>
Avatar billede dexxa Nybegynder
28. maj 2001 - 21:17 #6
LÆS Hvad jeg spørger om!!!!!
Tumbe! :)
Avatar billede bigo Nybegynder
28. maj 2001 - 21:25 #7
done.. ;-)
Avatar billede bigo Nybegynder
28. maj 2001 - 21:26 #8
så rent faktisk vil du - fra et asp site- includere kode fra et php site.. am i rite ?
Avatar billede dexxa Nybegynder
28. maj 2001 - 21:37 #9
Ja!
Og de ligger på to forskellige webservere

og....
<?php
include (\"http://domæne1.dk/inkluder.php\");
?> vil ikke virke da du ikke kan include eksternt!
Avatar billede bigo Nybegynder
28. maj 2001 - 21:46 #10
www.php.net/include

lidt længere nede er der et eks.


require
require_once



Last updated: Tue, 22 May 2001
view this page in English | Brazilian Portuguese | Czech | Dutch | French | German | Hungarian | Italian | Japanese | Korean | Spanish | Plain HTML


include()
The include() statement includes and evaluates the specified file.

If \"URL fopen wrappers\" are enabled in PHP (which they are in the default configuration), you can specify the file to be include()ed using an URL instead of a local pathname. See Remote files and fopen() for more information.

An important note about how this works is that when a file is include()ed or require()ed, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.

This happens each time the include() statement is encountered, so you can use an include() statement within a looping structure to include a number of different files.


$files = array (\'first.inc\', \'second.inc\', \'third.inc\');
for ($i = 0; $i < count($files); $i++) {
    include $files[$i];
}
   




include() differs from require() in that the include statement is re-evaluated each time it is encountered (and only when it is being executed), whereas the require() statement is replaced by the required file when it is first encountered, whether the contents of the file will be evaluated or not (for example, if it is inside an if statement whose condition evaluated to false).

Because include() is a special language construct, you must enclose it within a statement block if it is inside a conditional block.


/* This is WRONG and will not work as desired. */

if ($condition)
    include($file);
else
    include($other);

/* This is CORRECT. */

if ($condition) {
    include($file);
} else {
    include($other);
}
   




In both PHP 3 and PHP 4, it is possible to execute a return statement inside an include()ed file, in order to terminate processing in that file and return to the script which called it. Some differences in the way this works exist, however. The first is that in PHP 3, the return may not appear inside a block unless it\'s a function block, in which case the return applies to that function and not the whole file. In PHP 4, however, this restriction does not exist. Also, PHP 4 allows you to return values from include()ed files. You can take the value of the include() call as you would a normal function. This generates a parse error in PHP 3.

Example 11-1. include() in PHP 3 and PHP 4

Assume the existence of the following file (named test.inc) in the same directory as the main file: <?php
echo \"Before the return <br>\\n\";
if (1) {
    return 27;
}
echo \"After the return <br>\\n\";
?>
   



Assume that the main file (main.html) contains the following: <?php
$retval = include (\'test.inc\');
echo \"File returned: \'$retval\'<br>\\n\";
?>
   



When main.html is called in PHP 3, it will generate a parse error on line 2; you can\'t take the value of an include() in PHP 3. In PHP 4, however, the result will be: Before the return
File returned: \'27\'
   



Now, assume that main.html has been altered to contain the following: <?php
include (\'test.inc\');
echo \"Back in main.html<br>\\n\";
?>
   



In PHP 4, the output will be: Before the return
Back in main.html
   

However, PHP 3 will give the following output: Before the return
27Back in main.html

Parse error: parse error in /home/torben/public_html/phptest/main.html on line 5
   



The above parse error is a result of the fact that the return statement is enclosed in a non-function block within test.inc. When the return is moved outside of the block, the output is: Before the return
27Back in main.html
   



The spurious \'27\' is due to the fact that PHP 3 does not support returning values from files like that.


When a file is include()ed, the code it contains inherits the variable scope of the line on which the include() occurs. Any variables available at that line in the calling file will be available within the called file. If the include() occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function.

If the include()ed file is called via HTTP using the fopen wrappers, and if the target server interprets the target file as PHP code, variables may be passed to the include()ed file using an URL request string as used with HTTP GET. This is not strictly speaking the same thing as include()ing the file and having it inherit the parent file\'s variable scope; the script is actually being run on the remote server and the result is then being included into the local script.


/* This example assumes that someserver is configured to parse .php
* files and not .txt files. Also, \'works\' here means that the variables
* $varone and $vartwo are available within the include()ed file. */

/* Won\'t work; file.txt wasn\'t handled by someserver. */
include (\"http://someserver/file.txt?varone=1&vartwo=2\");

/* Won\'t work; looks for a file named \'file.php?varone=1&vartwo=2\'
* on the local filesystem. */
include (\"file.php?varone=1&vartwo=2\");             

/* Works. */
include (\"http://someserver/file.php?varone=1&vartwo=2\");




Men anyroads.. den bliver ikke nem.. jeg giver op.. giver mig.. sorry at jeg blandede mig ;-)
Avatar billede dexxa Nybegynder
28. maj 2001 - 21:50 #11
hehe
Avatar billede myplacedk Nybegynder
28. maj 2001 - 22:03 #12
Jeg aner ikke om ASP kan include eksterne filer, men hvis den kan, er det jo bare at lade PHP\'en outputte ASP-source...

<?
if($sog == \"reseller\")
{
print(\"variabel = \'Reseller løsninger bla bla..\';\");
}

(tilpas selv asp-syntaxen...)
Avatar billede dexxa Nybegynder
28. maj 2001 - 22:04 #13
forstår ikke dit forslag.!?
Avatar billede myplacedk Nybegynder
28. maj 2001 - 22:42 #14
Måske kan ASP hente ASP-kilde fra en anden server, og så eksekvere det.
Hvis du henter ovenstående PHP med parametren \"sog=reseller\", så vil outputtet (som ASP ser) være:

variabel = \'Reseller løsninger bla bla..\';

Hvis ASP\'en så eksekverer dette, vil du nu have en variabel tilgængelig, som indeholder noget PHP\'en har genereret.
Avatar billede dexxa Nybegynder
29. maj 2001 - 09:22 #15
kunne ikke bruge dit svar!
Avatar billede myplacedk Nybegynder
29. maj 2001 - 15:01 #16
Hvorfor ikke?
(Nysgerrig, plus svaret kan måske modificeres så du kan bruge det...)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester