PDA

View Full Version : [PHP] Stampare un define dentro un require_once


robertino_salemi
22-02-2014, 00:11
Salve a tutti,
ho un define definto come


define(SITE_URL, 'http://www.nomesito.it');


ed un

require_once('mappa.php);


Bene, se scrivo:

require_once(SITE_URL . 'mappa.php);


Non riesce a raggiungere il file, come mai?
Cosa c'è che non va?

Grazie.

lorenzo001
22-02-2014, 08:45
Ma gli apici ci sono tutti?

robertino_salemi
22-02-2014, 08:50
Scusatemi, errori di battiture mentre scrivevo nel forum:


require_once(SITE_URL . 'mappa.php');


L'errore ovviamente persiste...

lorenzo001
22-02-2014, 09:00
'/mappa.php'

manca un carattere / per separare le parti

robertino_salemi
22-02-2014, 09:27
Esatto, ma non va ugualmente.

La formattazione dovrebbe essere corretta così, giusto?

Tuvok-LuR-
22-02-2014, 12:41
il require è riferito al file system locale, non puoi indicare una risorsa http

airon
22-02-2014, 16:50
il require è riferito al file system locale, non puoi indicare una risorsa http

:read:
Anche perché altrimenti si potrebbe tirare giù facebook in locale :D

robertino_salemi
22-02-2014, 18:04
Immaginavo, quindi è un'operazione impossibile, tranne che passo il percorso assoluto scritto direttamente lì.

Grazie.

Tuvok-LuR-
22-02-2014, 18:43
puoi usare curl per caricare risorse remote, ovviamente avrai l'html processato, non il sorgente php

DanieleC88
24-02-2014, 10:27
il require è riferito al file system locale, non puoi indicare una risorsa http

Sicuro?

If "URL include wrappers" are enabled in PHP, you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Supported Protocols and Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including 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.

Ovviamente la cosa non è il massimo, anche in termini di sicurezza, e infatti c'è un bel "Security warning" poco più avanti... ma essendo PHP hai una grande libertà nello spararti nel piede. :p

robertino_salemi
24-02-2014, 11:05
Grazie a tutti per il vostro interesse.

La mia esigenza nasce dal momento in cui ho un sito multilingua, quindi avrò url del tipo nomesito.it/it o nomesito.it/en etc... quindi pensavo ad un path assoluto.

Daniels118
24-02-2014, 11:15
Io non l'ho mica capita la tua esigenza... devi utilizzare il path locale al posto dell'URL, non ha importanza se lo scrivi relativo o assoluto, basta che sia corretto.

robertino_salemi
24-02-2014, 11:46
Se ho un url del tipo www.nomesito.it allora basterà require('nomefile.php');

Ma se ho un url del tipo www.nomesito.it/it allora sarà require('../nomefile.php');

No?

Daniels118
24-02-2014, 12:00
Certo, va benissimo ;)

robertino_salemi
24-02-2014, 12:03
Quindi per costruirmi il percorso dinamicamente, forse dovrei usare:


$_SERVER['DOCUMENT_ROOT']


?

Daniels118
24-02-2014, 12:19
Sarebbe perfetto!

robertino_salemi
24-02-2014, 13:57
Infatti, allora procederò così! :)