how to add differents meta (opengrapg) tag to every dynamic created page (www.page.com/index.php?page=article&id=1), i tried to put this in article page:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta property="og:title" content="<?php echo $title?>" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://www.page.com/index.php?page=article&id=<?php echo $id ?>" />
<meta property="og:image" content="http://www.page.com/image.png" />
<meta property="og:site_name" content="eeeeee" />
<meta property="og:description" content="<?php echo $desc; ?>"/>
<meta property="fb:admins" content="blabla" />
</head>
but FB Linter cant see them - "Required Property Missing"
I simple include with switch function article.php page
$conlibrary="play/pages/" ;
IF(!isset($_GET['page'])){
$page = 'deafault';
} ELSE {
$page = $_GET['page'];
$findme = '&';
$pos = strpos($page, $findme);
IF ($pos ===true) {
$data = explode("&", $data);
$dest =$conlibrary."/".$data[0].".php";
IF (file_exists($dest)) {
$page = $_GET['page'];
} ELSE {
$page = '404';
}
} ELSE {
$dest =$conlibrary."/".$page.".php";
IF (file_exists($dest)) {
$page = $_GET['page'];
} ELSE {
$page = '404';
}
}
}
include($conlibrary . $page .".php");
ty
Your missing the ? in your URL...
www.page.com/?page=article&id=1
not
www.page.com/page=article&id=1
Related
I can get a BLOB image from my MySQL database but I want to show it as a preview image when I post to facebook. I don't want to save the image to my computer because I will end up with too many images. The closest I can get is showing a load of ascii code instead of the actual image. Is it even possible to achieve this? This is the code I have at the moment.
<?php
require_once($_SERVER['DOCUMENT_ROOT']."/includes/config.php");
$keys = htmlspecialchars($_GET['id']);
$query = "SELECT * FROM birdtabletop WHERE id='$keys' AND approvalMsg = 'Approved' LIMIT 1";
if(!isset($error)){
try {
foreach ($db->query($query) as $row) {
//set vars here
$tTitle = $row['tabletop_name'];
$tPicture = $row['tabletop_photo'];
}
} catch(PDOException $e) {
header('Location: login.php');
}
}
if(!isset($row)){
header('Location: login.php');
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<?php include_once("includes/analyticstracking.php") ?>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><?php echo $tTitle; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="">
<meta property="og:title" content="<?php echo $tTitle; ?>">
<meta property="og:type" content="website">
<meta property="og:url" content="https://www.finchkeeper.com/viewtabletop.php<?php echo "
?id=".htmlspecialchars(filter_input(INPUT_GET, 'id')); ?>">
<?php
if($tPicture != NULL){
echo '<meta property="og:image" content="data:image/jpeg;base64,'.base64_encode( $tPicture ).'"/>';
}else{
echo '<meta property="og:image" content="https://www.finchkeeper.com/images/tabletop.jpg">';
}
?>
<meta property="og:description" content="" />
Is there a way to use page $data variables in the template it's loaded in?
For instance - if I have a template that has a head like this:
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<title><?php echo $data['title']; ?> | ACME, Inc.</title>
</head>
My view is pages/home and the controller looks something like this:
public function index($data) {
$data = array();
$data['title'] = 'Home';
$this->load->view('pages/home', $data);
}
How do I get a parent template or sibling view to take on the page's variables?
I usually use the code below for meta data in page
In controller:
$page = new stdClass();
$page->title = "Your Page Title";
$page->desc = "Your page description";
$page->key = "keword1,keyword2,keyword3";
$page ->author = "Alex";
$data['page'] = $page;
$this->load->view('pages/home', $data);
In View:
<title><?php
if(isset($page->title)){
echo $page->title;
}
?></title>
<meta name="description" content="<?php
if(isset($page->desc)){
echo $page->desc;
}
?>"/>
<meta name="keywords" content="<?php
if(isset($page->key)){
echo $page->key;
}
?>"/>
<meta name="author" content="<?php
if(isset($page->author)){
echo $page->author;
}
?>"/>
content="<?php
if(isset($page->desc)){
echo $page->desc;
}
?>"/>
This is safe for not conflicting variable and easy to use.
I wand to build a simple dereferrer site like anonym.to
When you visit http://www.mydereferrer.tld/?http://www.sitename.tld you should be redirected to http://www.sitename.tld by a meta-refesh tag.
Here's what I have:
<?
if(($pos = strpos($_SERVER['REQUEST_URI'], '?')) !== false) {
$url = trim(substr($_SERVER['REQUEST_URI'], $pos + 1));
}
if (strlen($url) > 50) {
$url_short = substr($url, 0, 48) . "..";
} else {
$url_short = $url;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<?
if(!empty($url)) {
?>
<meta http-equiv="refresh" content="1; URL=<? echo $url ?>" />
<?
}
?>
<title>.. Redirecting</title>
</head>
<body>
<div id="container">
<?
if (isset($url)) {
?>
<h1>.. Redirecting</h1>
<p><? echo $url_short; ?></p>
<?
} else {
?>
<h1>.. No valid URL given</h1>
<?
}
?>
</div>
</body>
</html>
this works quite fine. But what security checks should I do?
What CBroe is referring to is that you just include $url and $url_short without any character escaping. Because of that you are susceptible to XSS. As a quick example assume $url is
www.google.com" /><body onload=alert('test1')><br style="
then
<meta http-equiv="refresh" content="1; URL=<? echo $url ?>" />
gets evaluated to
<meta http-equiv="refresh" content="1; URL=www.google.com" /><body onload=alert('test1')><br style="" />
OWASP has an excellent guide on how you embed untrusted data into your page.
I have to add noindex to some url's, this is my code at the moment:
<?php if ($metanoindex) { ?>
<meta name="robots" content="noindex,follow" />
<?php } elseif ($_SERVER['REQUEST_URI']=='/dolls/1/bestselling' ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } elseif ($_SERVER['REQUEST_URI']=='/dolls/1/bestselling/30' ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } elseif ($_SERVER['REQUEST_URI']=='/dolls/1' ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } else { ?>
<meta name="robots" content="index,follow" />
<?php } ?>
I wondered if there is a way to make an array of urls instead of repeating "else if" each time.
Try as below
<?php
$arr = array('/dolls/1/bestselling','/dolls/1/bestselling/30','/dolls/1');
if($metanoindex || in_array($_SERVER['REQUEST_URI'],$arr)){ ?>
<meta name="robots" content="noindex,follow" />
<?php
}
else {
?>
<meta name="robots" content="index,follow" />
<?php } ?>
PHP Manual: in_array()
$urls = array('/dolls/1/bestselling', '/dolls/1/bestselling/30', '/dolls/1');
if (in_array($_SERVER['REQUEST_URI'], $urls)) {
// Insert meta tag here
}
How can I add a different title, keyword and description in every page's <head> of my simple php website dynamically?
I have included file header.php in all of my pages, how can i know in what page the user in?
For example, I have php files register.php, and login.php, and I need different titles, keywords and descriptions.
I do not want use the $_GET method.
Thanks!
Set variables at the top of each page that will be read by header.php. Then insert the values of the variables in the right places in header.php. Here is an example:
register.php:
<?php
$title = "Registration";
$keywords = "Register, login";
$description = "Page for user registration";
include('header.php');
?>
header.php
<html>
<head>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<meta name="description" content="<?php echo $description; ?>" />
<title><?php echo $title; ?></title>
</head>
<body>
Put the output inside a function (within your header.php) and insert its parameters at appropriate places into the markup.
function html_header($title = "Default") {
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><?php echo $title ?></title>
</head>
…
<?php
}
you can try this:
for example the $page variable is your page name:
<?php
switch($page)
{
case 'home':
$title = 'title';
$keyword = 'some keywords..';
$desc = 'description';
break;
case 'download':
$title = 'title';
$keyword = 'some keywords..';
$desc = 'description';
break;
case 'contact':
$title = 'title';
$keyword = 'some keywords..';
$desc = 'description';
break;
}
if(isset($title))
{
?>
<title><?php echo $title; ?></title>
<meta name="keywords" content="<?php echo $keyword; ?>" />
<meta name="description" content="<?php echo $desc; ?>" />
<?php
}
else
{
?>
<title>default</title>
<meta name="keywords" content="default" />
<meta name="description" content="default" />
<?php
}
?>