How does phpinfo() change the title of the page permanently? - php

If you use phpinfo() in your page, you will notice it will change the title of your page? And even if you give the title of your page to be different it will not change. How is this done?

Is because phpinfo print <title>, is depend on how browser handle the tag rendering.
Chrome, Firefox and internet explorer is practicing FIFO.
So, do this
<title>my title</title>
<?phpinfo() ?>
is my title being set as browser page title
<?phpinfo() ?>
<title>my title</title>
Then above will set page title to phpinfo()

phpinfo outputs a complete HTML page, including a <head> section with <title>phpinfo()</title>. You can only have one <head> and one <title> per page, so I wouldn't even know how you'd attempt to change the title to anything else without producing a completely broken page to begin with.

put <title> tag above phpinfo(). Check the page source there will be two title tags , first one will be shown.

Related

Facebook debugger scraper doesn't understand PHP include

This is a weird one...
I have various php pages which includes head.php to display header tags, for example:
certificate.php
<html>
<head>
<?
$SEO_image = "custom_image.png";
include_once "head.php";
?>
</head>
...
</html>
head.php
...
<?
if(!isset($SEO_image)) $SEO_image = "default_image.png";
?>
...
<meta property="og:image" content="<?echo $SEO_image; ?>">
<meta property="og:image:width" content="200px">
<meta property="og:image:height" content="129px">
....
I include the head.php in many pages and when I load the site in a browser everything works according to plan. If the parent page first instanciates $SEO_image before the include_once "head.php" the page source shows me the correct image custom_image.png. Otherwise shows me the default_image.png.
But if I run the same url which in the browser displays custom_image.png by facebook's debugger scraper it says the og:image tag is default_image.png. This happens with all tags that use variables in the same way (first declared in the parent page to used inside the included php script).
Facebook scraper: https://developers.facebook.com/tools/debug
It's like if facebook's scraper is doing the impossible and somehow disassociating the variables in the parent pages from the head.php page.
What do you think can be happening here?
Thank you!
NOTE: I am aware that the og:image tag requires the entire url. I edited the code to exclude the site. As I mentioned, when viewing the page sources in a browser everything works properly.

PHP Include <head> and Social Media tags

I created a family website. I have the header for the entire site all the way through my main as a PHP INCLUDE. This is a must because I have a massive directory of fly down menus that need to change across the site when I change that one file.
Everything works beautifully except for one thing: I have unique articles where only on those pages I need unique meta tag OG information specific to that one page so the correct information is displayed when the article is shared on Facebook, Twitter, etc. When you use a PHP include across the entire site for the header, how do you change the unique meta OG data for select pages only?
I know putting a 2nd head tag wouldn't be ideal. Also, I would have to put it in the body given my include file for the header includes the top body tag.
Before I went and changed the coding logic of the site, I was hoping there is a straightforward solution to this I am no aware of (and I am a noob coder so that may be part of it).
I know I could put the main menu only in a file, and then call that menu file in a 2nd header file that is then itself called in an include across the entire site.. that would give me the latitude in those pages. But was hoping there is an easier answer like, "oh no, they meta OG tags can go in the body like this...." or something?
I would recommend setting the desired header information in PHP variables at the top of the page, and then include the PHP header file:
page.php:
<?php
$og_url = 'http://www.example.com';
include('header.php');
?>
header.php:
<html>
<head>
<meta property="og:url" content="<?php echo $og_url; ?>" />
</head>
This way, you can set unique social media information for each page, while still making use of the global <head> section from the header file. Keep in mind that you'll probably also want fallback behaviour in case your variables aren't referenced on every page that you call the header file from:
<meta property="og:url" content="<?php echo isset($og_url) ? $og_url : $_SERVER['DOCUMENT_ROOT']; ?>" />
While a document has to start with <html>, it's perfectly fine to set PHP variables before calling <html>; it's only content that's actually written to the DOM that you need to worry about.
Hope this helps! :)

IE not loading properly only the first time

I have an application that works perfectly in Chrome,Firefox and Safari, but when I load it on IE happens a strange thing: all the page is loaded on the left side and after one or two refresh it loads properly.
Here are two descriptive images:
And the second time (after one or more refresh) IE loads it like this:
Does anyone know why is IE having this behaviour?
Thank you.
I found the problem, it was quite simple.
I was calling my 'functions.php' as the very first code line (even before <!DOCTYPE html...). This file includes some javascripts function that CAN'T be loaded before <!DOCTYPE html (better between <head></head> tags).
Once I placed them between <head> tags the page is loading properly.
Thank you for the hints.

codeigniter letter at start of every page

I'm working on a website, which I have temporarily hosted here.
You'll notice the mystery letter 'a' I'm getting at the start of every page. I've gone through all the php files (controllers, views, models) and cannot locate where this letter is coming from. Another curiosity is that all the head content is not residing in the head tags when inspected with Firebug. It appears in the body tags, however it still functions correctly. Are these two issues related?
The only thing I have found from searching the internet is that perhaps some files have been saved as ANSI instead of UTF-8. I've tried 'saving as' all my php files as UTF-8 using my editor, but it is a very slow process. Any help debugging this situation would be appreciated.
EDIT- thanks for your response, #erman-belegu. It doesn't seem to be in any controller. For instance, I've set up a 404 redirect, with its own controller and view. The view looks like this:
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="No Page">
</head>
<body>
<h1>No page dude.</h1>
</body>
</html>
But when inspected with firebug, it looks like this:
<html>
<head></head>
<body>
a
<meta content="No Page" name="description">
<h1>No page dude.</h1>
</body>
</html>
I have encoded everything using UTFCast, and am still experiencing the same issue. Any help welcomed.
You see the head inside the body tag because the mysterious "a" is the first character of your output. It's put inside the body tag by the rendering engine of your browser, or by firebug.
If you find the cause of your "a" - almost certainly some content outside PHP tags - the head will return to normal in firebug.
Searching for the "a" is tricky.. I'm not sure how large your codebase is, but I'd say start by exiting the process right before output is sent. You should see only the "a". Then move the exit step by step untill your "a" disappears, and you'll find it.
Check your controllers at start or maybe any print somewhere. Check all your code on these pages because you print these "a ".
Also use UTF-8 without BOM. But, I think that you print it accidentally and dont think that this happens for any other reasons.

intermediate page before redirect to external links

i'm novice in php and already searched the forum for this and found something similar although i don't understand it
i have 2 external links http://www.hello.com and http://www.bye.com
on click on each link, i want to load an intermediate page (eg: redirect.php) for 5 second with a
message: "You are leaving misite.com. goodbye."
and then, make the correct to the correct external link that applies in each case.
i need:
1.- content of redirect.php
Continue to external link
Continue to external link
i'm sure it's wrong.
also, i don't know how to put a 5 seconds spinner (gif) an then make the redirection (step3)
2.- link users click on it. is it ok?
i have:
hello
not sure if it's correct
the link the users hit, tries to call the link in the redirect page, but i'm unable
well, the thing i don't know how to make it work and i really aprecciate an example
thanks
You should make your link to redirect.php, and add the "final destination" as a URL parameter, as you have already done. On redirect.php, use a meta tag in the head section that redirects (see here for an example).
EDIT: Code requested...
In your main php page, have your links as you already wrote:
Hello
Goodbye
In redirect.php, you need to add a meta tag in the <head>...</head> section of your HTML:
<html>
<head>
...
<meta http-equiv="refresh" content="5;url=<?php echo $_GET['link'];?>" />
...
</head>
<body>
<h1>You are leaving my site!</h1>
<img src="/images/spinner.gif" alt="spinner" />
</body>
</html>
and that's it. The meta tag "content" attribute contains the number of seconds before redirecting, and the address to redirect to.
Hope this helps.

Categories