A php Noob in need of some local server help - php

So i installed XMAPP to view my php site im developing for a php mysql class at my local college and I ran aground hours ago and have been searching frantically for answers since. whenever i try to view my site all i see is this
" . $row['tid'] . ""; echo $id; $thisName = "\n
" . $row['fname'] . " " . $row['lname'] ."
"; echo $thisName; $description = "\n
" . nl2br($row['description']) . "
"; echo $description; echo ""; } include ("footer.php"); ?>
or something similar. we host on a local server that has everything we need but cannot access it from our homes. I was wondering if anyone could lend me a hand?

It looks like you have an echo statement where you're using a single quote to open a string but not close it. For instance:
echo '" . $row['tid'] . ""; echo $id; $thisName = "
Go search in your source for something like this. I'd bet that this is your error.

Related

How do you display the stream name? [ICECAST]

I took a part of PHP code from a different Stackoverflow question, and it works perfectly.
<?php header>
//Display IceCast Server Stats
$server = "***********"; //IP (x.x.x.x or domain name)
$iceport = "8070"; //Port
$iceurl = "live"; //Mountpoint
$online = "<font color=green><b>ONLINE</b> </font><br />";
$offline = "<font color=red><b>OFFLINE</b></font><br />";
if($fp = #fsockopen($server, $iceport, $errno, $errstr, '1')) {
fclose($fp);
$ice_status=$online;
echo "<p><b>DJ:</b> $ice_status";
$stats = file("http://" . $server . ":" . $iceport . "/status2.xsl");
$status = explode(",", $stats[5]);
$artist = explode("-", $status[5]);
echo " " . $artist[1];
echo " - ";
echo " " . $artist[2];
echo "<br />";
// echo "<b>Listeners:</b> <b> " . $status[3] . "</b>";
echo "</p>";
//echo "<br />";
//echo "<p><a href=http://" . $server . ":" . $iceport . "/" . $iceurl . " target=new><b>Listen!</b></a></p>";
} else {
$ice_status=$offline;
echo "<p><b>DJ:</b> $ice_status";
}
?>
<hr />
</center>
I'm trying to add the stream name, which is currently:
echo "DJ: $ice_status";
This displays DJ: ONLINE, but I want it to say DJ: (DJ Name/Stream Name)
I do believe its variables from status2.xsl, but I'm a complete noob at this, and can't seem to figure out how to use it. Could anyone tell me what streamname variable would be?
I was also wondering, is it possible to make it so the "nowplaying.php" refreshes, but my whole web page doesn't? I've tried an iframe, but it makes it look really bad, and has errors.
What my website looks like at the moment: https://i.stack.imgur.com/luc4O.jpg
I'd suggest having a look at TheFineManualâ„¢:
http://icecast.org/docs/icecast-2.4.1/server-stats.html#xslt
Especially the part about status-json.xsl. Make sure you are running an up to date version of Icecast. Icecast is available from all major Linux distributions in up to date packaging. Xiph provides independent packaging, which is useful if there are no up to date packages for a distribution, e.g. shortly after an Icecast release.
status2.xsl was an example file, and a bad one at that. It was removed from newer Icecast versions.

php in header url error

I have just a quick question. i was using a normal html link tag to redirect to a paypal checkout page and it was working fine even when i had php inside the url. but when i was using it in a php header
the url cuts off where i enter the php.
header('location: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXX&lc=UK&item_name=<? echo $product . " " . $server ?>&amount=<? echo $xprice1; ?>%2e00&currency_code=GBP&button_subtype=services&no_note=0&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHostedGuest');
You are placing the PHP code inside of the location redirect as a string. The code is not being evaluated as PHP.
Try this instead:
<?php
$url = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXX&lc=UK&item_name=" . $product . " " . $server ."&amount=" . $xprice1 . "%2e00&currency_code=GBP&button_subtype=services&no_note=0&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHostedGuest";
header('location: ' . $url);
Or, you could keep it in one line like so:
<?php
header('location: ' . "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXX&lc=UK&item_name=" . $product . " " . $server ."&amount=" . $xprice1 . "%2e00&currency_code=GBP&button_subtype=services&no_note=0&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHostedGuest");
header('location: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXX&lc=UK&item_name=<? echo $product' . " " . '$server ?>&amount=<? echo $xprice1; ?>%2e00&currency_code=GBP&button_subtype=services&no_note=0&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHostedGuest');
This may solve your problem. Please dont forget to tick the answer right if it works.

Can't use value on the outside from inside a function with PHP [duplicate]

This question already has answers here:
Making global var from inside a function in PHP
(3 answers)
Closed 9 years ago.
I have a function in location.php with this code:
$isp = $ipInfo["isp"];
$country = $ipInfo["country"];
$state = $ipInfo["state"];
$town = $ipInfo["town"];
echo "ISP: " . $isp . "<br>\n";
echo "Country: " . $country . "<br>\n";
echo "State: " . $state . "<br>\n";
echo "Town: " . $town . "<br>\n";
I have a file named test.php. If I use this code:
<?php
include('location');
echo "ISP: " . $isp . "<br>\n";
echo "Country: " . $country . "<br>\n";
echo "State: " . $state . "<br>\n";
echo "Town: " . $town . "<br>\n";
?>
inside test.php I get the following output:
ISP: dslb-094-219-040-096.pools.arcor-ip.net
Country: DE - Germany
State: Saarland
Town: Schiffweiler
ISP:
Country:
State:
Town:
The second ISP, country, state and town are in test.php and do not show anything and the first ones are inside location.php. The whole problem is, I can't use a variable created inside the function on the outside or in another php file. How can I use a variable on the outside?
It has to do with global and scope?
Sorry if I am confusing, but it's almost 3:30 am and I am getting nuts
You can use the global keyword to do this
function my_func()
{
global $isp,$country,$state,$town;
//do stuff to variables
}
echo $isp.$country.$state.$town;
Something like that would work. Although a better option would probably be returning the variables in a return statement.
--edit--
Just made a working mockup
p1.php
<?php
function a()
{
global $b,$c,$d;
$b='hi';
$c='bye';
$d='what';
}
a();
?>
p2.php
<?php
include 'p1.php';
echo $b.$c.$d;
?>
There shouldn't really be any reason something like this wouldn't work for you.
You shouldn't try to lift variables over include statements, it makes for messy code. include isn't like a function call.
Typically the kind of files you want to include are files that have just function or class definitions in them. And then you'll probably want to use include_once.
include can be useful for things like templates, where you might actually end up repeating the same file but for just PHP code: no.
The proper way would look like this:
// location.php
function printIPInfo($ipInfo) { // THIS is a function
$isp = $ipInfo["isp"];
$country = $ipInfo["country"];
$state = $ipInfo["state"];
$town = $ipInfo["town"];
echo "ISP: " . $isp . "<br>\n";
echo "Country: " . $country . "<br>\n";
echo "State: " . $state . "<br>\n";
echo "Town: " . $town . "<br>\n";
}
// test.php
include_once('location.php');
printIPInfo($ipInfo);
I am not entirely sure why you are having problems
I often have a "Dim.php" file to define constant strings and then include using:
include("location.php");
Using the .php extension may fix your problem?

win32_query_Service_status

I am trying to connect to a remote server Win 2003 using a PHP script I have come across from php.net below and returns error 5 which is permissions, the code works great when I query localhost.
Has anyone ever come across this issue before or know a work around? Once I know I can connect I plan to monitor services and then be able to restart them with monitor script.
$servicename ="crmskidata";
$machine ="crm2011";
//print_r (win32_query_Service_status($servicename,$machine));
echo $servicename;
$sray = win32_query_Service_status($servicename,$machine);
echo "<br>";
print_r ($sray);
echo "<ul>";
echo "<li>Service Type: " .$sray[ServiceType] . "</li>";
echo "<li>CurrentState: " .$sray[CurrentState] . "</li>";
echo "<li>Controls Accpeted: " .$sray[ControlsAccepted] . "</li>";
echo "<li>Win32 Exit Code: " .$sray[Win32ExitCode] . "</li>";
echo "<li>Service Specific Exit Code: " .$sray[ServiceSpecificExitCode] . "</li>";
echo "<li>Check Point: " .$sray[CheckPoint] . "</li>";
echo "<li>Wait Hint: " .$sray[WaitHint] . "</li>";
echo "<li>Process Id: " .$sray[ProcessId] . "</li>";
echo "<li>Service Flags: " .$sray[ServiceFlags] . "</li>";
Added the webservers mavhine name to the local administrators group on the machine i was trying to connect to.

How would you do a code-escape in PHP?

I have a huge list of stuff for a glossary ( about 17 pages worth ) that I have to put into an XML file. So I decided I'd use php to make it. My code works, except where ALL the XML code is, it doesn't show because it's trying to render it. Help?
$arg=explode("\n", $strang);
echo count($arg);
for ($i=0;$i<=count($arg);$i=$i+3)
{
echo "<word id='" . $arg[$i+1] . "'>";
echo "<desc>" . $arg[$i] . " - " . $arg[$i+2] . "</desc>";
echo "<pic></pic>";
echo "<audio></audio>";
}
I assume by render it you mean in your browser? If so, you'll need to escape the characters so they will be interpreted literally rather than as markup.
Check out htmlspecialchars and htmlentities
use CDATA construction:
echo "<desc><![CDATA[" . $arg[$i] . " - " . $arg[$i+2] . "]]></desc>";
If this is your entire script, fastest way would probably be to swap all of the <'s with <
$arg=explode("\n", $strang);
echo count($arg);
for ($i=0;$i<=count($arg);$i=$i+3)
{
echo "<word id='" . $arg[$i+1] . "'>";
echo "<desc>" . $arg[$i] . " - " . $arg[$i+2] . "</desc>";
echo "<pic></pic>";
echo "<audio></audio>";
}

Categories