How to create a link that will display the contents of a PHP variable?


 
Thread Tools Search this Thread
Top Forums Web Development How to create a link that will display the contents of a PHP variable?
# 1  
Old 02-08-2018
How to create a link that will display the contents of a PHP variable?

Greetings,

I've wrote a script that when you point your browser to a machine it displays info about itself. Below is a small snippet of the script:

Code:
<?php
$iloipaddr = `ipmitool lan print | grep 'IP Address  ' | cut -d\: -f2 | sed 's/ //'`;
$sftwrlist = `rpm -qa | sort`;
?>

<p><a href="http://<?php echo$iloipaddr;?>">ILO link: You must be on the same private subnet for this link to work.</a><p/ >

What I've been trying to figure out is how to create a link on the resulting page that will display the $sftwrlist variable contents. I've tried various combinations of href but I'm not sure at this point it's the correct way to accomplish my goal. Any suggestions or hints would be appreciated.

---------- Post updated 02-08-18 at 08:56 AM ---------- Previous update was 02-07-18 at 10:54 AM ----------

Unable to figure out how to get that link in the original PHP script I opted to create the $sftwrlist in a separate PHP script and link to it from my original script. New software list script:
Code:
<?php
$sftwrlist = `rpm -qa | sort`;
?>

<b><u>Installed software</u></b>
<pre><?php echo print_r($sftwrlist);?></pre>

Line in the original to get the list:
Code:
<p><a href="sftwr.php">Installed Software</a><p/ >

Not the way i wanted to do it as it would have been nice to keep my goal to a single PHP script but this will have to do.
# 2  
Old 02-08-2018
Why not just put $sftwrlist = `rpm -qa | sort`; in the same script...?
# 3  
Old 02-08-2018
I had it there originally but the problem was I didn't know how to create a link that would display it. So as you can see, I made the software list a completely separate script because I knew how to create that type of link in the original script.
# 4  
Old 02-09-2018
Ah, suddenly I see what you want.

Well, you can get different values from the same webpage by putting different parameters into it, i.e.
Code:
http://site/path/to/webpage.php

,
Code:
http://site/path/to/webpage.php?variable1=value1

, etc. Put special links like
Code:
<a href="?variable1=value1">something</a>

and that should refer to the same page with a parameter.

These values will appear in the superglobal array $_GET.

Code:
<?php

if(!array_key_exists("mode", $_GET)) {
  print("<!-- Default values -->");
  print("<a href="?mode=first">Something Else</a>\n");
  exit();
}

switch($_GET['mode']) {
case "first":
        printf("First Mode Data\n");
        break;
default:
        printf("Unknown Mode\n");
        break;
}
?>

# 5  
Old 02-09-2018
For clarity here's a larger chunk of the original script:
Code:
<?php
$hostname = shell_exec('hostname');
$manufacturer = `dmidecode -s system-manufacturer | tail -1`;
$model = `dmidecode -s system-product-name | tail -1`;
$product = `dmidecode | grep SKU | cut -d: -f2`;
$serialno = `dmidecode -s system-serial-number | tail -1`;
$iloipaddr = `ipmitool lan print | grep 'IP Address  ' | cut -d\: -f2 | sed 's/ //'`;
$sftwrlist = `rpm -qa | sort`;
?>

<p><b><u><big><?php echo $hostname;?></big></u></b><br/ >
<b>Manufacturer: </b><?php echo $manufacturer;?><br/ >
<b>Model: </b><?php echo $model;?><br/ >
<b>Serial Number: </b><?php echo $serialno;?><br/ >
<b>Product Number:</b><?php echo $product;?><br/ ><p/ >
<p><a href="http://<?php echo$iloipaddr;?>">ILO link: You must be on the same private subnet for this link to work.</a><p/ >
<b><u>Installed software</u></b>
<pre><?php echo print_r($sftwrlist);?></pre>

It's the last line I can't figure out. I've tried using href but it seems suited to point to another page which is why I created the separate script and changed the last line to:
Code:
<p><a href="sftwr.php">Installed Software</a><p/ >

Mainly because I have no idea how to put a line in the original script that will simply display the value of $sftwrlist. I'm pretty new to HTML and PHP and especially a rookie when it comes to mixing the two in the same script.
# 6  
Old 02-09-2018
You use echo or printf to print a string, like echo $string; or printf("<tag>%s</tag>", $string); Alternately you can let the program itself to the printing like system("hostname");

Conceivably you could write this whole thing in shell and cut out the middleman, too.
# 7  
Old 02-09-2018
Correct, I could but this a PHP script that is in the machine's /var/www/html directory that you point your browser at. Which is why I'm trying to figure out how to make the last line of the script a link that you click to get thee installed sftwr on the machine.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

2. UNIX for Dummies Questions & Answers

HTML: Display contents of file using Variable

<tr><td bgcolor=#D7EBAD><b>Instructions :</b></td> <td>`cat temp.txt`</td></tr> Hi Experts, I have an requirement of displaying file contents in HTML mail , for which am using the above approach, Where as the output is kind of not as expected. If there are 5 lines in the file, in the... (4 Replies)
Discussion started by: scott_cog
4 Replies

3. UNIX for Advanced & Expert Users

Cannot create a link with the same name

Hi - Our system admin cannot create a link to NAS with one particular name but he can create with other names. What might be the cause? Regards ---------- Post updated at 11:30 AM ---------- Previous update was at 11:29 AM ---------- It says permission denied. (2 Replies)
Discussion started by: w020637
2 Replies

4. Shell Programming and Scripting

Display array contents on a new line

ksh eg arrayname=(1 2 3 4 5) I'm trying to display the individual contents of an array on a new line without using a loop, using one line of code. output 1 2 3 4 5 (3 Replies)
Discussion started by: squrcles
3 Replies

5. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

6. UNIX for Dummies Questions & Answers

What are the contents of a symbolic link?

Hiii... I wanna know "What are the contents of a symbolic link?"....... From google I dint get a good answer....that's why I posts here...... Thanking you. Krishna (1 Reply)
Discussion started by: krishnampkkm
1 Replies

7. Web Development

Display the contents of a table.

Dear Friends, Am an newbie to this domain. I have a table which is filled with contents which i need to be updated with,so am trying to design a flow which would read the data from the table and mail it to me at regular intervals. I could make out the flow using mailx command but want to... (3 Replies)
Discussion started by: gokulj
3 Replies

8. UNIX for Dummies Questions & Answers

Display the contents of an array

Hi i have just registered So i am at university studying forensic computing and we have to learn c++ i have never done anything with c++ before and i am abit stuck i need to create a programme to display the contents of an array of characters forwards and in reverse Can anyone help me... (1 Reply)
Discussion started by: RossMc
1 Replies

9. UNIX for Dummies Questions & Answers

How to display contents of folder when 'cd' is used

Hi, I am a new learner of Unix. I am currently working on a Solaris 8 machine. Earlier, when I use 'cd <folder name>' command, I am not only able to change the folder but also able to see the contents of the folder as if a 'ls -lt' command was executed. However, since a week, suddenly this... (3 Replies)
Discussion started by: mumashankar
3 Replies
Login or Register to Ask a Question