I am a bit new to PHP.
I am trying to filter a ICS file for events containing a certain string. The following script seems to do that job just fine:
<?php
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=fodda2009.ics');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
function icsFilter($paramUrl,$filterstring) {
$icsFile = file_get_contents($paramUrl);
$icsData = explode("BEGIN:", $icsFile);
foreach($icsData as $value) {
if (strpos($value, "VEVENT") === FALSE) {
echo "BEGIN:";
echo $value;
}
else {
if (strpos($value, $filterstring) !== FALSE) {
echo "BEGIN:";
echo $value;
}
}
}
}
?>
<?php echo icsFilter('http://cal.laget.se/ALMTUNAISHOCKEYSKOLA.ics','dda 2009'); ?>
VEVENT
DESCRIPTION:Dummy info
DTEND;TZID=W. Europe Standard Time:20001010T121500
DTSTAMP:20001005T192952Z
DTSTART;TZID=W. Europe Standard Time:20001010T110000
SUMMARY:Dummy event
UID:200abc01010T110000-8918999#stackoverflow.com
END:VEVENT
END:VCALENDAR
I am hosting the script at http://mydomain.dyndns.com/mycalendar.php. When I enter that URL into Google Calendar (other calendars -> add by URL) I receive a message "[your URL] is not a valid URL".
Is this caused by the script ending in .php?
Do I need to convince my server (Apache) to call the php script at a http://mydomain.dyndns.com/mycalendar.ics URL? How? Is there something else I am doing wrong?
OK, this is a little embarrassing...
The code above works just fine, the source of my error was that I left out the "http://" from the URL. Thus Google Calendar complained that it wasn't a good URL. cough Adding "http://" to my URL worked wonders :)
I'll leave the script here, maybe someone else wants to have a simple PHP script to filter an existing iCal file and serve it to Google Calendar.
Related
As soon as I entered a site, my browser (chrome) downloaded this script. It's not obfuscated and not too long, and I think it's harmless, but I don't know PHP so i'm not sure. The file was called csync.php.
Chrome made it seem like this was the only file downloaded. Is it possible this is not true?
Could someone shed some light on what this is doing?
<?php
require_once("config/config.php");
require_function("util/StaticFunctions.php");
require_function("service/ServiceFactory.php");
require_function("bo/BoFactory.php");
require_function("data/DataFactory.php");
require_function("util/UtilFactory.php");
require_function("data/AkamaiLoggingService.php");
include 'config/setup/config-setup-skenzo.php';
include 'config/skenzo_request_variables.php';
header('P3P:CP="NON DSP COR NID CUR ADMa DEVo TAI PSA PSDo HIS OUR BUS COM NAV INT STA"');
header('Content-type: text/html');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: -1');
$visitorInfo = BoFactory::getVisitorInfo();
$vsid = $visitorInfo->getVisitorId();
$dataNames = VisitorInfo::$VSID_DATA_NAMES;
$mName = BoFactory::getInboundHttpRequest()->getSanitizedValueOfParam('type');
$mValue = BoFactory::getInboundHttpRequest()->getSanitizedValueOfParam('ovsid');
$vsCk = VISITOR_ID;
$vsDaCk = VISITOR_DATA;
$sepVal = VisitorInfo::$VALUE_SEP;
$sepTime = VisitorInfo::$TIME_SEP;
$vsDaTime = VisitorInfo::$VSID_DATA_TIME;
echo '<html> <head></head> <body> <script type="text/javascript" >';
$vsyncConf = array (
"vsCk" => $vsCk,
"vsDaCk" => $vsDaCk,
"sepVal" => $sepVal,
"sepTime" => $sepTime,
"vsDaTime" => $vsDaTime
);
echo "var vsyncConfig = " . json_encode($vsyncConf) . ";\n";
include(SKENZO_MEDIA_DIR. '/js/util/C2/modules/mnvdata.js');
echo '</script>';
echo "</body></html>";
if(AKAMAI_LOG_POSTBACK == $_SERVER['SERVER_NAME'])
{
define('AKAMAI_BULK_LOGGING', TRUE);
define('TEST_ENGINE_FROM_SERVING', '1');
try
{
$akLogService = new AkamaiLoggingService();
$akLogService->handleAkamaiBulkData();
echo '<!--var logged = 1;-->';
}
catch(Exception $e)
{
error("RTBLOG AKAMAI ERROR: " , $e , LOG_ALERT);
echo '<!--var logged = 0;-->';
}
}
else
{
if(AKAMAI_LOG_ORIGIN == $_SERVER['SERVER_NAME'])
{
echo '<!--var logged = 1;-->';
}
else
{
define('AKAMAI_BULK_LOGGING', TRUE);
define('TEST_ENGINE_FROM_SERVING', '1');
try
{
$akLogService = new AkamaiLoggingService();
$akLogService->handleGetRequests();
echo '<!--var logged = 1;-->';
}
catch(Exception $e)
{
error("RTBLOG AKAMAI ERROR: " , $e , LOG_ALERT);
echo '<!--var logged = 0;-->';
}
}
}
?>
The server you're visiting is poorly configured. As a result, instead of executing the PHP, the server sent it to your browser. Browsers don't execute PHP so you're safe.
If you care about the site you were visiting, the nice thing to do would be to contact support and refer it to this post.
A similarly named csync.php file has been reported in a couple of places online over the last couple of days. This, along with its reference to AKAMAI (a huge content delivery network), suggests that the mis-configured server isn't the 1st party site you were actually on, but a 3rd-party server that the site, along with many others, relies on.
File's apparent source: http://qsearch.media.net/csync.php
Similar reports (Google): https://encrypted.google.com/search?q=csync.php+download
I also saw this file drop into my downloads. The source is qsearch.media.net. If you visit media.net, you'll see it is part of the internet advertisement ecosystem. It's likely that there is a bug in one of their scripts. Sites using media.net's service then incidentally cause your computer to download this php file.
This is absolutely not server error of any websites, it is because my browser also download this script from multiple sites,one of them are from speedtest.net, i don't know what's hack is going on.
Here is the POSTFILE code in App inventor:
https://www.dropbox.com/s/9gndlxibrg8f85b/uploadimage.jpg?dl=0
Here is the PHP script:
<?php
$ACCESSKEY="uhuh";
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
if($_GET['p']==$ACCESSKEY){
// this is the workaround for file_get_contents(...)
require_once ($_SERVER['DOCUMENT_ROOT'].'/php/PHP_Compat/Compat/Function/file_get_contents.php');
$data = php_compat_file_get_contents('php://input');
$filename = $_SERVER['DOCUMENT_ROOT']."/images/".$_GET['filename'];
if (file_put_contents($filename,$data)) {
if (filesize($filename) !=0) {
echo "File transfer completed";
} else {
//header("HTTP/1.0 400 Bad Request");
echo "Error: File is empty.";
}
} else {
//header("HTTP/1.0 400 Bad Request");
echo "Error: File transfer failed.";
}
} else {
//header("HTTP/1.0 400 Bad Request");
echo "Error: Access denied"; //reports if accesskey is wrong
}
?>
I am using PHP_Compat located here:
http://pear.php.net/package/PHP_Compat/
When I tried using desktop emulator, it returns error "411: content length required". But when i try using apk on the phone, after selecting image from phone and pressing UPLOAD the filename (of the right image) gets created on the server in right folder too, but the size is always zero and the script returns "error transfer failed".
Even rang GoDaddy and thought it might be due to some server or php setting but they could not help much. I thought maybe changing the PHP variable upload_tmp_dir might help but cant do it.
I really need this work for my app so Hope someone can help.
I am trying to return a value using php and AJAX but I get the following returned when doing so. This part of my code has been functional in previous projects so I am a little stumped as to why it is happening now.
The returned value:
‹������«VÊÏV²2ÔQ*.)V²qjÜ¥5¼���
it should return something like this:
{"ok":1,"status":"ok"}
The PHP I am using:
$response = array('ok' => 0);
if($results)
{
$response['ok'] = 1;
$response['status'] = ($visible == 'visible') ? 'ok' : 'no';
}
ob_clean();
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($response, true);
exit;
Now if I removed the code and put into its own file it works fine. I have all files and database set to UTF-8 also.
You have a duplicate closing parentheses on line 2.
It should be:
$response = array('ok' => 0);
if($results)
{
Fixing that, your code works for me:
{"ok":0}
And if I force $results = true; :
{"ok":1,"status":"no"}
I feel so stupid now, I was running ob_gzhandler within my ob_start();
Apologies to all.
I am having trouble executing this code in my index.php.
It says 'CartAction not set'
I need your help php gurus. I can display any files you need to fix this error.
Here is the code:
// Handle AJAX requests
if (isset ($_GET['AjaxRequest']))
{
// Headers are sent to prevent browsers from caching
header('Expires: Fri, 25 Dec 1980 00:00:00 GMT'); // Time in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/html');
if (isset ($_GET['CartAction']))
{
$cart_action = $_GET['CartAction'];
if ($cart_action == ADD_PRODUCT)
{
require_once 'C:/vhosts/phpcs5/presentation/' . 'cart_details.php';
$cart_details = new CartDetails();
$cart_details->init();
$application->display('cart_summary.tpl');
}
else
{
$application->display('cart_details.tpl');
}
}
else
trigger_error('CartAction not set', E_USER_ERROR);
}
else
{
// Display the page
$application->display('store_front.tpl');
}
It's because your code is expecting a parameter named 'CartAction' in the url
Example:
www.yoursite.com/?CartAction=ADD_PRODUCT
The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character. Source
You check if $_GET['CartAction'] has a value ( from the above url this superglobal variable has the value 'ADD_PRODUCT' )
What #Mackiee (in comments) and your error message are both telling you is that the problem is that there is a query parameter missing. The URL that calls this needs to include either ?CartAction=ADD_PRODUCT or &CartAction=ADD_PRODUCT
I am trying to stream data read from a file to chrome client. I am able to stream data successfully but my responses are getting cached and I want to prevent that from happening. This situation is there because my flat file contains data entries which are independent of each other and i want to treat them likewise. For example, my file contains :
{idle_time:94125387364,system_time:98954710321,user_time:3683963615}
{idle_time:94125387789,system_time:98954710456,user_time:3683963845}
{idle_time:94125387876,system_time:98954710678,user_time:3683963986}
so instead of getting
{idle_time:94125387876,system_time:98954710678,user_time:3683963986}
(THIRD ENTRY)
as xmlhttprequest.responsetext, I receive
{idle_time:94125387364,system_time:98954710321,user_time:3683963615} <br/>
{idle_time:94125387789,system_time:98954710456,user_time:3683963845} <br/>
{idle_time:94125387876,system_time:98954710678,user_time:3683963986}
NOTE : I am not worried about breakline tags and blankspace.
My PHP script looks like this,
test.php
<?php
set_time_limit(0);
$filename = 'D:\Smoke_Test\data.txt';
function flush2 (){
echo(str_repeat(' ',256));
// check that buffer is actually set before flushing
if (ob_get_length()){
#ob_flush();
#flush();
#ob_end_flush();
}
#ob_start();
}
$file_last_modified_time = 0;
while(true)
{
$modified_time = filemtime($filename);
$processor_info = "";
if ($file_last_modified_time < $modified_time)
{
header("Expires: Sun, 20 Jan 1985 00:00:00 GMT"); // date in the past
header("Cache-Control: no-cache");
header("Pragma: no-cache");
$file_last_modified_time = $modified_time;
$handle = fopen($filename,"r");
$processor_info = fgets ($handle);
fclose ($handle);
#ob_clean();
echo $processor_info."<br/>";
//flush2();
}
flush2();
sleep(1);
clearstatcache(true, $filename);
}
?>
and my html page looks like this:
Home.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script type="text/javascript" language = "javascript">
function read_file ()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 || xmlhttp.readyState==3 ) //&& xmlhttp.status==200)
{
handle_data (xmlhttp.responseText);
}
}
xmlhttp.open("POST","test.php",true);
xmlhttp.send();
}
function handle_data (input)
{
document.getElementById("txtResponse").innerHTML=input;
}
</script>
</head>
<body>
<p>
<input type="button" id="dtnSendRequest" value="Send Request" onclick="read_file()"/>
</p>
<p>
response : <span id="txtResponse"></span>
<!-- <input type="text" id="txtResponse" width="500"/> -->
</p>
</body>
</html>
try adding this to the top of your php file
header("Expires: Sun, 20 Jan 1985 00:00:00 GMT"); // date in the past
header("Cache-Control: no-cache");
header("Pragma: no-cache");
Use this to force no-cache:
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
Make sure you call this before sending any output.
You cant avoid whats happening with responseText. Its the nature of Http Streaming (not local or any caching) makes that happen. I found a very good article which states my situation as well as the solution.
The article is http://ajaxpatterns.org/archive/HTTP_Streaming.php
Following paragraph contains my situation as well as solution for it.
"The responseText property of XMLHttpRequest always contains the content that's been flushed out of the server, even when the connection's still open. So the browser can run a periodic check, e.g. to see if its length has changed. One problem, though, is that, once flushed, the service can't undo anything its output. For example, the responseText string arising from a timer service might look like this: "12:00:00 12:01:05 12:01:10", whereas it would ideally be just "12:00:00", then just "12:01:05", then just "12:01:10". The solution is to parse the response string and only look at the last value. To be more precise, the last complete value, since it's possible the text ends with a partial result. An example of this technique works in this way. To ease parsing, the service outputs each message delimited by a special token, "#END#" (an XML tag would be an alternative approach). Then, a regular expression can be run to grab the latest message, which must be followed by that token to ensure it's complete"