I am using joomla 3.2 with jumi 3, here is a sample of how I call my script via jumi
{jumi [myscript.php] [foo] [bar]}
here is myscript.php
<?php
echo $jumi[0];
echo $jumi[1];
?>
above script is successfully able to print the values as foo & bar
but if I modify the same to include another script ans try to get the variables in that script then it does not have any value
here is new myscript.php
<?php
include 'foobar.php';
?>
foobar.php
<?php
echo $jumi[0];
echo $jumi[1];
?>
this fails to print the values. help me find if I am missing something
Related
I am very new to PHP programming. I am trying to write this custom php code in Drupal and seeing this weird behavior. Basically I have two php files which users can hit and the first php file is showing output from the second one. I am not including (include) the second file in the first one.
Home.php - The first file (outputs 'why am i executing' at the end)
<?php include 'HomeView.BL.inc';
//Other links to access second file
?>
HomeView.BL.inc
<?php
include 'db.inc';
include 'dao.inc'; - has a class called IDA_Map
?>
FacultyInternshipDetail.php - The second file
<?php
include 'InternshipDetailView.BL.inc';
?>
InternshipDetailView.BL.inc
<?php
echo "why am i executing";
include 'db.inc';
include 'dao.inc';
?>
Apart from the output from the second file, I am also seeing this error - Cannot redeclare class IDA_Map.
I have read in other posts about 'include_once' but didn't expect re-declaration error since the class (IDA_Map) is declared once per request.
Thank you.
Flip all these to require_once.
<?php require_once'HomeView.BL.inc';
//Other links to access second file
?>
HomeView.BL.inc
<?php
require_once'db.inc';
require_once'dao.inc'; - has a class called IDA_Map
?>
FacultyInternshipDetail.php
<?php
require_once'InternshipDetailView.BL.inc';
?>
InternshipDetailView.BL.inc
<?php
echo "why am i executing";
require_once'db.inc';
require_once'dao.inc';
?>
include breaks when you try to include the same file twice.
Also look up composer and into using a php framework so you dont have to worry about any of this!
Is it possible to send PHP code to the browser?
The site currently have PHP and jQuery available.
For example:
<?php echo "HELLO"; ?>
this will show as HELLO on the client side:
Hello
I want to make it so the client/browser will receive:
<?php echo "HELLO"; ?>
Possible structure:
index.php (Main Page)
edit.php (A page that will show the source code of index.php including the PHP ad allows me to edit it (and will save server-side))
This is for a temporal on-the-site source code editing (because I cannot access cPanel in certain places).
edit.php
<?php
$cont = file_get_contents('index.php');
echo $cont;
?>
Not like such. Whenever the interpreter sees
<?php echo "HELLO"; ?>
In order to get the contents from an external file you could use file_get_contents('filename.php');
or
<?php echo htmlentities(file_get_contents('filename.php')); ?>
PHP has a built in syntax highlighter which could help you when outputting the PHP code.
$string = '<?php echo "abc..."; ?>';
highlight_string($string);
Alternatively you could output a PHP file with syntax highlighting by using
highlight_file('index.php');
I have a php file as my main page, and I want to pass a php variable to an external js file that is drawn with php. I have several php'd external js files that work fine but are "not" dependent on php from the main page. Some are dependent on JavaScript from the main page, but I want to move away from that. My intentions are to keep the main page clean by limiting the amount of JavaScript on it, by increasing dynamics, and to allow better site management.
Maybe if I understood the natural relationship of external files to the calling page, i dun know. For instance, the code below is some of my current code, and it assumes the external js script, being the php file it is, sees "functions.php" and $sel_entity from the main page. However, it does not seem to work that way. I am guessing maybe functions.php needs to be included in the external file, but no clue with $sel_entity. I am aware I could echo variables to a js variable on the main page, but I need something more dynamic for my plans. Any help here would be great. Thank you!
For instance, the main page is something like:
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php $sel_entity = $_GET['entity']; ?>
...//bunches of code
<script type="text/javascript" src="javascripts/lines.php"></script>
Then the js file lines.php is something like:
<?php
Header("content-type: application/x-javascript");
$job_set = get_jobs($_GET['entity']);
while ($job = mysql_fetch_array($job_set)) {
echo "
var jobLine";
echo $job["Project_ID"];
echo " = [new google.maps.LatLng(lati, longi),
";
$jobIdCoords = get_jobCoord_by_id($job["Project_ID"]);
echo " new google.maps.LatLng(";
echo $jobIdCoords['lat'] . ", ";
echo $jobIdCoords['long'] . ")]; ";
}
...// bunches more code
?>
The best way would be to use $_SESSION, but be sure to start the session in the "js" file.
<?php
session_start();
$_SESSION["foo"] = "bar";
?>
<script type="text/javascript" src="javascripts/lines.php"></script>
And then the JS file:
<?php
Header("content-type: application/x-javascript");
session_start();
echo 'var foo = "'.$_SESSION["foo"].'";';
?>
alert(foo);
However, you should be able to also use $_GET like so:
<script type="text/javascript" src="javascripts/lines.php?foo=bar"></script>
And the "JS" file:
<?php
Header("content-type: application/x-javascript");
echo 'var foo = "'.$_GET["foo"].'";';
?>
alert(foo);
Okay, so let's say I have a webpage with a defined php $variable, and then I use include("variableEchoed.php), which just echos $variable.
How do I accomplish this? Simply doing what I said above doesn't work.
Again, I want to use an included php file to echo a variable onto another webpage where that variable is defined.
Index.php
<?php
$variable = 'test';
include('variableEchoed.php');
?>
variableEchoed.php
<?php
echo($variable);
?>
The result will be test.
yes its easily doable.
$ cat 1.php
<?
echo $x;
?>
$ cat 2.php
<?
$x="hello world";
include("1.php");
?>
$ php 2.php
hello world
Write a function in the file to echo that $variable.. Call the function just after including the file.
I have 2 files:
create.php:
<html>
<body>
<?php
require("Test.php");
hello();
echo "does this work?";
?>
</body>
</html>
and Test.php:
<?php
function hello(){
echo "hello";
}
?>
But when I open create.php, nothing prints (not even "does this work?". If I call hello() from Test.php it works fine. That is, it doesn't seem to be executing code after the include. What am I doing wrong?
edit: the code seems to work fine in my IE 8 install, but not in my FF 5 install (which, admittedly, has way to many addons).
edit again: the issue was that the page cache needed to be refreshed. There was never a problem. The code works. sorry, all.
Do yourself a favour and turn on error reporting. Place the following code at the beginning of create.php and let us know the error message(s) you receive.
<?php
ini_set('display_errors', 'on');
error_reporting(E_ALL);
require_once('Test.php');
?>
My guess is that it is a path issue.
First of all, you do not need the html tags in your PHP-File. Second: you need to execute your function. Now you only defined it. Try
Test.php
<?php
function hello(){
echo "hello";
}
hello();
?>
And make sure that both files are in the same directory.
use dirname(FILE) instead of a stright include
eg
if i have a dir
/var/www/html/include
and test.php resides in includes and your script is in html then use dirname(__FILE__).'/includes/test.php
if you need to go back in a dir the use dirname(dirname(__FILE__))
depending on how many levels.
it also makes it dynamic so command line and browser will always fin the file
Try the code below for create.php
<?php
require('Test.php');
?>
<html><body>
<?php
hello();
echo 'does this work?';
?>
</body>
</html>