THis may be super basic, but I have not been able to resolve this after spending hours!
I am running PHP 7 on Ubuntu 16.1.
The PHP file is EXACTLY as follows
<?php
header("Content-type: application/javascript");
header("HTTP/1.1 200 OK");
ExpandShortLink();
function ExpandShortLink()
{
// get URL
$URL_To_Expand = $_REQUEST['url'];
// for short links, get the full links
// get full URL
$arr_URL_Header = get_headers($URL_To_Expand, 1);
$strLink = $arr_URL_Header['Location'];
//echo $URL_To_Expand;
//print_r($arr_URL_Header);
if ($strLink) {
if (is_array($strLink)) {
$Full_URL = array_pop($strLink);
} else {
$Full_URL = $strLink;
}
} else {
$Full_URL = $URL_To_Expand;
}
echo $Full_URL;
}
--> produces the url I enter as a "url" parameter on desktop. But nothing on mobile!
On some reading, I found that in sometimes PHP interprets everything after "//" as a comment and that may be happening here. But then why does it happen on mobile only? Also, andy suggestions on resolving this will be great!
Thanks much for your help,
You can see this live here
If you click this on desktop, you will see http:// example. com. However, on mobile it will return http:
Not sure if this qualifies as answer, but I wanted to put a note here for anyone else who may be facing a similar problem.
I was using the PHP pasted above for an ajax call. I tried using text/plain instead of application/json and now it works across all browsers and all devices (as far as I could test).
Not sure why application/javascript was causing problems on mobile chrome, but I think text/plain makes sense as I was just passing back a text string instead of a javascript.
As I said it probably is not the fully qualified answer, but hopefully it helps someone in future!
Related
I know this question has been asked millions of times, but please actually take the time to understand my problem before marking as duplicate or closing.
So I am using the following code. For some reason it gets all of the correct header information the first time I run the code EXCEPT for content-length. The second time I run the code it actually gets it correctly. I am retrieving the images from Facebook API if that changes anything.
function remote_filesize($url) {
$data = get_headers($url, 1);
if(isset($data['Content-Length'])) {
return (int) $data['Content-Length'];
}
else {
return -1;
}
}
Edit
Gotta love when you get downvoted with no explanation. Personally I think it should be required to provide a reason.
Anyway, this is still an issue, but in case anyone googling this needs a solution for getting the remote filesize, I would suggest using this awesome snippet from the PHP docs http://php.net/manual/en/function.filesize.php#114952
Sounds like a server caching issue.
So you may have to issue a full GET request instead of just a HEAD request.
Also, maybe check different casing -- 'content-length:' -- lowercase.
I have been struggling with a couple of strange issues in my free time project I'm workig on. It's my first "big" PHP / JS project, and to be honest I'm using ajax for the first time so I might be just missing something.
Anyways, here how it is. I'm programming a very simple invoicing system using PHP and jQuery technologies with mPDF library to generate an PDF file from HTML/CSS. I'm using mainly Session variables inside the template that gets sent to mPDF to generate an PDF invoice.
Issue I'm experiencing is on Chrome for Android, tested on latest version on OnePlus One. The Session variables are not showing in the PDF itself. I think it worked like once or twice totally at random. My friend with Android device and Google Chrome also confirms same issue.
test.php:
<?php
session_start();
error_reporting(E_ALL);
if (!isset($_SESSION['GLO_IS_LOGGED_IN'])) {
header("Location: index.php");
exit;
}
include('libs/mPDF/mpdf.php');
ob_start();
include('protected/templates/template.php');
$data = ob_get_clean();
$mpdf = new mPDF();
$mpdf->WriteHTML($data);
$mpdf->Output('protected/invoices/Faktura ' . date('j-m-Y-H-i-s') . '.pdf');
$mpdf->Output('Faktura ' . date('j-m-Y-H-i-s') . '.pdf', 'D');
unset($_SESSION['VAR_DESCRIPTION_ARRAY']);
unset($_SESSION['VAR_AMOUNT_ARRAY']);
unset($_SESSION['VAR_PRICE_ARRAY']);
unset($_SESSION['VAR_TO_ADDRESS']);
unset($_SESSION['VAR_INVOICE_NUMBER']);
Here is generateInvoice.php file that you might have noticed in the invoice-script.js:
<?php
session_start();
error_reporting(E_ALL);
if (!isset($_SESSION['GLO_IS_LOGGED_IN'])) {
header("Location: index.php");
exit;
}
if (!empty($_POST['invoice-number'])) {
$_SESSION['VAR_INVOICE_NUMBER'] = trim($_POST['invoice-number']);
} else {
echo('Please add invoice number');
exit;
}
if (!empty($_POST['to-address'])) {
$_SESSION['VAR_TO_ADDRESS'] = ($_POST['to-address']);
} else {
echo('Internal Error');
exit;
}
$_SESSION['VAR_DESCRIPTION_ARRAY'] = $_POST['invoice-description'];
$_SESSION['VAR_AMOUNT_ARRAY'] = $_POST['invoice-amount'];
$_SESSION['VAR_PRICE_ARRAY'] = $_POST['invoice-price'];
I don't want to make this post very-long so I'll stop posting any code snippets here. Believe me that I have done everything I could to find out myself what's going on and it feels really bad that I cant figure it out myself and that I need to ask others for help. Anyways thanks for any feedback and help. Cheers!
'invoice-form' doesn't contain any fields - the input tags should be within the form
Ok people, I think I have found a solution for this.
Commenting away all of the unset methods at the end in test.php solved the Chrome for Android issue.
I don't understand why this was happening in the first place. Why were the session variables unset BEFORE the invoice was generated? They shouldn't be, right? Or I am really missing something? I know I shouldn't ask for clarification in my own answer but I think at this point I really need to.
Cheers and thanks to IanMcL for solving my Edge issue!
This may be hard to help me with but I'm out of options and have no hair left so here goes;
I have this simple part in my program where if a check box is disabled and the user is using the site on a device like an iPad they will get an alert box popup if they touch the check box. The problem that I'm having is that it works as expected on one domain but then on another domain it just flashes very quickly then goes away.
Because I don't have a Mac computer I can't use the Safari Web Console installed to see if any errors are coming up.
Here's the code to generate the alert;
if ($device == 'TAB') {
echo "<div id='" . preg_replace('/[^a-zA-Z0-9]/', '', $menu_name) . "OV'
class=\"overlay\" onClick=\"alert('My message');\"></div></div>";
} else {
echo "</div>";
}
Any ideas of why this would work in one place and not the other and anything that I can do to try to get the iPad to give me more info to what's going on here?
Here is where it works, interactive-floor-plan dot com/ifp.php?width=633&ProductID=1
and here is where it doesn't
plangator dot com/demo/ifp.php?width=633&ProductID=1
Your code seems completely fine to me, although your echo is a little bit unclear, because it's on one line. The problem should be somewhere else on your page. Try to find out what's happening with firebug. Here's a SO post about it.
iPad firebug lite or similar
Both links on that page seem useful to me.
Good luck!
Im currently coding a design tutorial site for developers and I have a snippet of code that basically throws a small alert on the page if the end-user is using an outdated version of IE on the screen.
As useless as it sounds, it's what the client wants. Oh well.
Basically, I can't get the damn this to close when you click the "Close this box" link. Here is the code. Any suggestions?
<?php
// IE6,7,8 string from user_agent
$ie6 = "MSIE 6.0";
$ie7 = "MSIE 7.0";
$ie8 = "MSIE 8.0";
// detect browser
$browser = $_SERVER['HTTP_USER_AGENT'];
// yank the version from the string
$browser = substr("$browser", 25, 8);
// html for error
$error = "<div class=\"error\" id=\"error\"><strong>Alert:</strong> It appears that you
are using Internet Explorer 6, 7, or 8. While you may still visit this website we
encourage you to upgrade your web browser so you can enjoy all the rich features this
website offers as well as other websites. Follow this link to <a
href=\"http://www.microsoft.com/windows/downloads/ie/getitnow.mspx\"><strong>Upgrade
your Internet Explorer</strong></a><br /><div class=\"kickRight\"><a href=\"javascript:
killIt('error');\"> Close This Box</a></div></div>";
// if IE6 set the $alert
if($browser == $ie6){ $alert = TRUE; }
if($browser == $ie7){ $alert = TRUE; }
if($browser == $ie8){ $alert = TRUE; }
?>
And then you add this into the BODY wherever you may want it:
<!-- IE6 Detect Advise Notice -->
<?php if($alert){ echo $error; } ?>
<!-- // end IE6 Detect Advise Notice -->
I can't get the damn this to close. I don't know what the problem is. It may be the there is javascript trying to close a PHP error box. I don't know c-based languages so I don't know. Any help is appreciated
Your close button is attempting to fire a JavaScript function called killIt() with a parameter of 'error'. I'm going to guess that you haven't included that function on the page, or that there's an error in it.
Just add the killIt javascript function to HTML. It would not remove any PHP code at server-side, but rather HTML output of PHP code in the browser. You haven't shown us the code for killIt, but my guess is that it either hides or removes the DIV that PHP prints.
I'm trying to write a sitemap.php which acts differently depending on who is looking.
I want to redirect crawlers to my sitemap.xml, as that will be the most updated page and will contain all the info they need, but I want my regular readers to be show a html sitemap on the php page.
This will all be controlled from within the php header, and I've found this code on the web which by the looks of it should work, but it's not. Can anyone help crack this for me?
function getIsCrawler($userAgent) {
$crawlers = 'firefox|Google|msnbot|Rambler|Yahoo|AbachoBOT|accoona|' .
'AcioRobot|ASPSeek|CocoCrawler|Dumbot|FAST-WebCrawler|' .
'GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby';
$isCrawler = (preg_match("/$crawlers/i", $userAgent) > 0);
return $isCrawler;
}
$iscrawler = getIsCrawler($_SERVER['HTTP_USER_AGENT']);
if ($isCrawler) {
header('Location: http://www.website.com/sitemap.xml');
exit;
} else {
echo "not crawler!";
}
It looks pretty simple, but as you can see i've added firefox into the agent list, and sure enough I'm not being redirected..
Thanks for any help :)
You have a mistake in your code:
$crawler = getIsCrawler($_SERVER['HTTP_USER_AGENT']);
should be
$isCrawler = getIsCrawler($_SERVER['HTTP_USER_AGENT']);
If you develop with notices on you'll catch these errors much more easily.
Also, you probable want to exit after the header
Warning: Cloaking can get you in trouble with search providers. This article explains why.
http://develobert.blogspot.com/2008/11/php-robot-check.html