Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP logic not working
2014-06-20, 09:02 (This post was last modified: 2014-06-20 09:08 by jhonny.)
Post: #1
PHP logic not working
Hi Guys,

I'm trying to get iPXE working with PHP and MYQSL.

For some reason the PHP logic does not seem to be working.

I've got the following code in a php file that ipxe chain boots:
What its supposed to do is grab the serial number of the server and assign it to the variable: serversn
Code:
<?php
header("Content-type: text/plain");
echo "#!ipxe\n\n";

$serversn = "\${serial}";

The problem is when i then do:

Code:
echo $serversn;

The output will look something like this:

Code:
ABCDEFG

So the output is 7 alpha numeric characters long

however when i run:

Code:
echo strlen($serversn);

The output is equal to 9 !!!! instead of 7 !!!!

No idea why that is, so i tried to add some padding on either side of the $serversn variable by doing the following:

Code:
echo str_pad($serversn, 9, "X", STR_PAD_RIGHT);
echo $serversn;

The output should be: ABCDEFGXX
The output is still the original 7 alphanumeric characters: ABCDEF
Its only until that i change the str_pad parameter to 10 that one X will show up:

Code:
echo str_pad($serversn, 10, "X", STR_PAD_RIGHT);
echo $serversn;
OUTPUT is: ABCDEFGX

Can anyone advise what the heck is going on ? why is the count incorrect ?
I've also tried doing the following:

Code:
$serversn = substr($serversn,0,7);

That should cut the string contents of the $serversn variable to the first 7 characters.
Instead what happens is when i echo out $serversn, it returns the following:

Code:
${seria

The output is 7 characters long but the "value" of the variable is lost.

What is going on here ?
Find all posts by this user
Quote this message in a reply
2014-06-20, 11:25
Post: #2
RE: PHP logic not working
(2014-06-20 09:02)jhonny Wrote:  Hi Guys,

I'm trying to get iPXE working with PHP and MYQSL.

For some reason the PHP logic does not seem to be working.

I've got the following code in a php file that ipxe chain boots:
What its supposed to do is grab the serial number of the server and assign it to the variable: serversn
Code:
<?php
header("Content-type: text/plain");
echo "#!ipxe\n\n";

$serversn = "\${serial}";

I think the problem is the calling factor. ${serial} is a place holder for the iPXE calls, so can the reason why the output is 9 characters is because the actual information stored in serversn is:
${serial}, literally. Which, as it happens, is 9 characters.

The way I pass variables like such back to my php scripts is to send it back in the url.

So I might have something like:
PHP Code:
print "#!ipxe\n";
print 
"chain http://192.168.1.2/boot.php?serversn=\${serial}\n"

Then I use the GET or POST var of servsn, this should now be set to the serial, not literally set to ${serial}.

So my Logic would contain, to check it, something like:
PHP Code:
if ($_GET['serversn'])
{
print 
"#!ipxe\n";
print 
"echo My system's serial number is: ....".$_GET['serversn']."\n";

Hope this helps.
Visit this user's website Find all posts by this user
Quote this message in a reply
2014-06-20, 12:01 (This post was last modified: 2014-06-20 12:04 by jhonny.)
Post: #3
RE: PHP logic not working
AWESOME ! Thank you so much !

I use the following command to invoke the php script and it works like a charm !:

Code:
chain http://192.168.1.2/boot.php?serversn={serial}

Now when i run:

Code:
echo strlen($_GET['serversn']);

I get the correct length Smile

I wonder if $_GET['serversn'] can be assigned to a variable ?
YEP I CAN ! Sweeeeet !

Code:
$serversn=$_GET['serversn'];
print "echo $serversn";
Find all posts by this user
Quote this message in a reply
2014-06-20, 12:45
Post: #4
RE: PHP logic not working
If you want see a somewhat complicated, but functional, php script that dynamically creates the boot script, you could take a look at this file:
https://sourceforge.net/p/freeghost/code....class.php
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)