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

Tags
web

 
Thread Tools Search this Thread
# 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.

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
awk to create variables to pass into a bash loop to create a download link cmccabe Shell Programming and Scripting 8 09-27-2016 01:51 PM
HTML: Display contents of file using Variable scott_cog UNIX for Dummies Questions & Answers 4 10-25-2013 01:34 PM
Cannot create a link with the same name w020637 UNIX for Advanced & Expert Users 2 09-12-2013 10:54 PM
Create a Link for a directory narayanv Solaris 5 08-06-2013 05:32 PM
Display array contents on a new line squrcles Shell Programming and Scripting 3 07-16-2013 12:56 PM
Folder contents getting appended as strings while redirecting file contents to a variable vivek d r Shell Programming and Scripting 2 03-29-2013 05:13 AM
Not able to create a link in /etc/rc3.d in Solaris 10 muraliinfy04 Solaris 5 03-19-2013 07:55 AM
SED - Create mailto: link Nigel_R Shell Programming and Scripting 5 07-21-2011 03:17 PM
What are the contents of a symbolic link? krishnampkkm UNIX for Dummies Questions & Answers 1 03-08-2010 09:15 AM
Display the contents of a table. gokulj Web Programming 3 10-06-2009 10:10 AM
Display the contents of an array RossMc UNIX for Dummies Questions & Answers 1 10-31-2008 02:25 PM
How to display contents of folder when 'cd' is used mumashankar UNIX for Dummies Questions & Answers 3 03-06-2008 07:42 PM
Create Symbolic Link lesstjm UNIX for Dummies Questions & Answers 2 03-21-2005 03:36 PM