Capture php variable from (Index1.php) To (Index2.html) - php

I try to capture the value of $app_id with the $_POST method to Index2.html with the code below and I can't.
The php code in html page don't change the color and that is the signal that the server doesn't work! I'm using Dreamweaver cs6 as editor
Index1.php:
$app_id = $_POST["appID"]
Index2.html:
<label for="appID"><?php $_POST['appID'] ?></label>

Is your server configured to run HTML files as PHP files? You're trying to run a PHP code inside a HTML file! You should rename index2.html to index2.php and run it inside an Apache server, or configure your Apache to run HTML as PHP. Also, index2 must be the action of index1 form.
UPDATE
How to parse HTML as PHP?

Related

what is basically happening in a php page

Let us consider the following html :
<!doctype html>
<html>
<body>
<form method="POST" action="submit.php">
<input name="name" placeholder="Enter your name">
<button type="submit">Submit</button>
</form>
</body>
Now to my understanding this code passes a list of arguments to a the php file which is mentioned in the action attribute of the method .
I understand that the code file is in the server system .
Now let us consider the code for submit.php as follow :
<?php
$name = $_REQUEST['name'];
?>
<!doctype html>
<html>
<body>
Hello <?php echo $name;?>
</body>
</html>
These codes are taken from an answer to my last question .
Now after the submit button is clicked . The client requests for a new page from the server .
I wanted to know what exactly is happening here . Does the server sends this code file to the browser and the php code is executed in the browser or submit.php , generates an html file according to the php code in it and that html file is sent to the client ?
Where is the code getting executed in the browser or in the server . With what I have read till now gives a feel that the code is being executed in the server but to be just sure .
Further , if the case is like the latter , i.e., the inputs are sent to server and the server based on the php code generates an html file that is sent back to the browser , then isn't it a bit inefficient in sending requests the server even for smaller changes ?
So what exactly is happening and where is the code getting executed ?
The PHP source is on the server and remains there. It is executed there, and the result (which is typically HTML, but can be anything else too), is sent as a response to the browser, so you got that right.
The advantage is that the PHP code itself is hidden to to user, and it can do advanced stuff like accessing files and databases which are hidden, and usually unaccessible directly for your website visitor.
The PHP code may be accidentally exposed when PHP is not set up properly. In that case, the code won't run but may be returned as plain text by accident. If you ever see PHP code in your browser, it's almost certainly due to an incorrect server set-up.
Even a small change should usually be done by the server. Theoretically it's inefficient to do those requests all the time, but in reality a request is not a big deal. If you only want to update the page itself, without doing anything special to the server, you could use JavaScript which can run in the browser as part of your page, and which can manipulate the loaded HTML document.
The whole process or execution life cycle can be explained in the following two steps:
Step-1:
Server-side PHP blocks enclosed in <?php ?> tags are executed and removed from the code base on the server on every request.
Step-2:
Client-side script and HTML tags left in step-1 are send for execution and display in the browser.
I hope the explanation is easily understandable now.

How to embed codeigniter script into external php script

l have a index file of my website in
localhost-->mywebsite-->index.php (this is my external script)
and i have build a registration form with codeigniter.
I can use the registration form using url http://localhost/codeigniter/index.php/form.
But how can i attach that registration form into my website index file.
using include_once"../codeigniter/index.php/form"; in my external php script(index.php of my website) is not working.
However if i make that 'form' the default controller file and use the following code from external php script
include_once "codeigniter/index.php"; it works well. but what if i need other controller files but not just 'form'?
Update:
I can also link to that file from external php script as:
<a href="codeigniter/index.php/form>Register</a>.
But not include. Whenever i include it displays no such file.
So if i understood you correctly you want to use codeigniter's form in some other php website, actually idea to do such thing is wrong (as you can't normally control your form action link etc better to build same for in other website directly), but answer for your question is following trick
Place this code in your other website where you want to have codeigniter form included
$output = shell_exec('php ABSOLUTE_PATH/codeigniter/index.php form index');
// where "ABSOLUTE_PATH" is absolute path to your codeigniter project
// "form" is your controller name
// "index" action name
echo $output; // will echo form html generated by codeigniter
In localhost-->mywebsite-->index.php, you could try this:
<?php include_once('/codeigniter/index.php/form'); ?>
If not you can move your index.php code into a codeigniter view and set it up that way.
try using below code...
<?php $data = file_get_contents("http://localhost/codeigniter/index.php/form/");
$html_encoded = htmlentities($data);
echo $html_encoded;
?>
In the above code we get all contents of the url in $data variable and then use htmlentities on that for html encoding...

Run Qt generated executable (EXE) through php (LINUX)

Sorry, this question must be repeated, it already asked the following link, but the answer is not cleared.. So can anyone please solve this problem???
exe not giving output in php
I am trying to call a Qt generated executable file through PHP code which fails to run the exe.. The same exe runs on double-click and through command line..
Below is my code
<?php
$exec_cmd = exec('"./myEXE"');
?>
<html>
<body>
<form>
<input type="submit" value="RUN" onclick="$exec_cmd"/>
</form>
</body>
<html>
Thank You...
PHP is a server side language. It means that the php code is compiled and executed in the server and the output is sent to the client.
What you are trying to do is to use PHP as client-side language, like JavaScript.
The porgram is executed when the page is displayed and you want it to be displayed once the user clicks on the button, for that you must use JavaScript.
I would use AJAX to make the request to the server so it can execute the program but if you don't want to use javascript you can set the form to redirect the page with a GET or POST parameter and check in PHP if that parameter is set

What is the correct syntax to echo php within javascript

What is the correct syntax to echo out some php within a javascript function?
I can't directly echo php in your Javascript because, the JS code is executed on the end user machine not on your backend. However you can echo some php code before the end user receives the JS source code, in other words, generate your JS code with php and serve it as .js file.

PHP - Defaulting form field value to the current date

I'm trying to default a value in a field to the current date, but my code:
<?php
echo '<input type="text" name="makeupassignment" size="50" value="'.date("m/d/y").'">';
?>
is only printing this:
';
?>
Looks to me that the web page is not running through the PHP interpreter. Check out the source for the web page. Do you see the PHP source code when you click "show source" in your browser?
I think what happens is that your browser parses this as follows:
open tag whose type is ?php
two fields named "echo" and "'<input"
then fields with values: type="text", name="makeupassignment", size="50", and value="'.date(", and then m/d/y").'"
then there is the closing tag >
and then the rest is output verbatim
I would guess that PHP is not enabled/installed on the webserver you're testing with. View source on that page and you'll see all your code, I bet
Basically, PHP is not parsing the page for it's code.
Is the script you are running a .html or a .php script? Make sure it's the correct suffix. I find that Firefox won't open a page that is .php (unless i'm accessing it via localhost).
Is PHP running? Check by running php -v in a console/terminal window.
Is Apache (/IIS/lighttpd etc.) running?

Categories