Whats the mistake here? - php

It is probably a silly mistake but i'm into splits because of it :(
Language : PHP 5.4.7 \n Framework: CodeIgniter 2.1.3 , SDK: Facebook PHP SDK 3.2.2
Please consider the following Controller function:-
public function index()
{
// $this->__construct();
$data['profile'] = $this->_facebook->api('/me?fields=id');
$this->load->view('user_profile',$data);
}
And the corresponding view (user_profile.php) :-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Showing the user profile</title>
</head>
<body>
<?php
//echo print_r($user_profile,TRUE);
echo '<IMG SRC="http://graph.facebook.com/'. $profile['id'] . '/picture" HEIGHT=32 WIDTH=32 /> ';
?>
</body>
</html>
The above code shows the profile picture in Internet Explorer but in Chrome the page is blank. On viewing page source, it is blank.

I would start with writing cleaner html.
<img src="http://graph.facebook.com/<?php echo $profile['id']; ?>/picture" alt="Profile Photo" height="32" width="32" />
Don't capitalize tags and img requires an alt attribute. I always quote attribute values, even when they're numbers.

Related

Add Wordpress Iframe of 3rd party company which provide me search, and search results page

Yes, I know something like this has been asked over here before and I have searched but the one that is closest to what I'm trying to achieve doesn't have an answer anywhere.
So what I need is really simple.
I have a WordPress site and I want to integrate Iframe of 3rd party company which provide me search, and search results page.
I need some help with put the search on section and the search results on hidden field or somthing until we have some results to show.
I have got 2 pages from 3rd party company as follow:
Search.html
<pre>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<iframe src="http://www.3rd_party_url/Default.aspx?urlresult=http://www.3rd_party_url/result.html" scrolling="no" width="350px" height="280px"></iframe>
</body>
</html>
</pre>
Result.html
<pre>
<html >
<head>
<title></title>
<meta charset="utf-8" />
<script type="text/javascript">
function GetQuery() {
var url = window.location.href;
url = url.substring(url.indexOf("?"))
iframe = document.getElementById('myIframe');
iframe.src = "http://www.3rd_party_url/pleasewait.aspx" + url;
}
window.onload = function ()
{
GetQuery();
}
</script>
</head>
<body>
<iframe id="myIframe" width="100%" height="800px" src=""></iframe>
</body>
</html>
</pre>
Not sure how to move on from there. I'd really appreciate some help.
Thanks in advance!

laravel print a view without displaying it in browser

in my laravel project i need to take print out of a doctor's prescription. and for that i have already created the header part and saved in database. when the user clicks on the printer icon next to a div then the content inside that div needs to be printed with the saved header.
the method is used is: in the view part which contain the printer icon
<div class="AnswerBlock"><div class="NmaeDate">
<span class="name"><?php echo 'Prescription :'; ?></span><span style="float:right;"><img src="<?php echo asset('images/footericons/printout.png'); ?>" title="prescription1" alt="take print" width="20" height="20"></span>
<div class="answer">
<?php echo stripslashes($data1->prescription1);?>
</div>
</div>
</div>
in the user controller:
public function anyPrintPrescription($eid='',$no=''){
$drpres='';
$prs = DB::table('appoint')->where('id','=',$eid)->first();
if($no=='1'){
$drpres = $prs->prescription1;
}
elseif($no=='2'){
$drpres= $prs->prescription2;
}
elseif($no=='3'){
$drpres = $prs->prescription3;
}
$presheader = Admin::where('id','=',$prs->d_id)->pluck('prescription_header');
return View::make('con.printout_prescription')->with(array('presc'=>$drpres,'phead'=>$presheader));
}
and the view is :
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
.print:last-child {
page-break-after: auto;
}
</style>
</head>
<body onload="window.print()">
<div class="print"><?php echo $phead;?></div>
<div class="print"><?php echo $presc;?></div>
</body>
</html>
The output i'm getting is : when the print icon is clicked the printer option prompt window is opening. but at the same time the browser goes to the view url and displays it.
Is anyone knows how to make the window not displaying the view ?
This isn't really a Laravel or even a PHP question, it's a matter of what you can and can't do with a browser.
A browser can't print something without viewing it. The only thing that I can suggest is to open the view in a new window or tab (change the code that calls back to the view) and have it close after the print is done.

Page reapets it self when using include

So Lately i was working on a website on LocalHost Using XAMPP Application.
So i created header.php with the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="A short description." />
<meta name="keywords" content="put, keywords, here" />
<title>Website Name</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="menu">
<a class="item" href="index.php">Home</a>
<a class="item" href="../forum/">Forums</a>
<a class="item" href="live-chat.php">Live Chat</a>
<a class="item" href="Login.php">Log In</a>
<a class="item" href="Register.php">Register Now!</a>
<div id="userbar">
<?php
error_reporting(E_ALL & ~E_NOTICE);
include 'search.php';
if($_SESSION['signed_in'])
{
echo 'Welcome <b>' . htmlentities($_SESSION['user_name']) . '</b>. Not you? <a class="item" href="logout.php">Log out</a>';
}
?>
</div>
</div>
<div id="content">
And a Login.php with this code ( Here is the 4 lines of it ) :
<?php
include 'connect.php';
include 'header.php';
etc..... php code....
Ok so the problem is When i try to open the login.php in web browser i got the code in header.php duplication many many times like it don't end duplicating it self and if i open the source code of login.php i will got unlimited number of the code used in header.php like all the source code is header.php repeatedly.
So I'am asking you guys for help on how to fix this and what is the error ??
NOTE: Sorry if their was a thread duplication but i didn't know on what to search exactly.
If you want anymore information I'am ready.
Thanks all much appreciated
Use
include_once('header.php');
everywhere instead. It will check to see if the file has already been included.
use require_once instead, it will load the file just once, and only if needed.
You have more info here

getting image with php and displaying in html

i know it is so simple problem but eventually it isn't working and i am a newbie. in the index.html, a swf sends an image and displayImage.php(below code) should display it on another page. why isn't it working??
<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
$no=0;
while (file_exists("images/$no.jpg"))
$no++;
header('Content-Type: image/jpeg');
$image = $GLOBALS["HTTP_RAW_POST_DATA"];
file_put_contents("images/".$no.".jpg", $image);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-9" />
<title>Your Image</title>
<link href= "style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="logo"></div>
<div id="body"></div>
/////////display image//////////
<img src="images/<?$no.".jpg?>">
</body>
</html>
You don't echo the filename (and you have a quoting error, but this could be a typo):
<img src="images/<?php echo $no ?>.jpg" />
Assuming that storing the file actually works.
<img src="images/<?=$no.".jpg"?>">
This might be the issue. The line below the "display image" comment, should probably read:
<img src="images/<?= $no ?>.jpg">
Could be that you're using XHTML strict. IMG tags can't be unclosed like in normal HTML. You have to end it with a /> instead. (it's supposed to fail catastrophically when you make an error but it only does that when you send the right MIME type header to treat it as XML, so treated as text you may get unpredictable results.....). If it's printing the name of the file (like images/1.jpg) then you know that it's parsing the inline PHP correctly....
i deleted the line "header('Content-Type: image/jpeg');" and it works!

Creating custom "html"-tags for CMS?

I am working with a CMS for a web app in PHP, that has the needs of shortening the process for inserting (embedding) stuff, like a video from youtube or vimeo by wroting the following, which are stored in the database:
<youtube id="wfI0Z6YJhL0" />
Which would output the following after some sort of replace:
<!-- Custom formatting before object !-->
<object width="640" height="385"><param name="movie" value="http://www.youtube-nocookie.com/v/wfI0Z6YJhL0&hl=sv_SE&fs=1?rel=0&color1=0xe1600f&color2=0xfebd01"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/wfI0Z6YJhL0&hl=sv_SE&fs=1?rel=0&color1=0xe1600f&color2=0xfebd01" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
<!-- Custom formatting after object !-->
How could I do this in PHP?
I've written a class that does exactly what you ask for my own cms. I've uploaded the src for you as although I've never released it the source is released under a BSD style license. Custom Tags
It basically allows you do do exactly what you ask for. In the class there are some example custom tags so I won't paste code here. Let me know how you go.
Edit 1: Example Code as requested. :-)
Edit 2: I should add it supports buried custom tags.
Edit 3: It also supports inline templating and tag substitution, ie
<ct:inline some="attribute">
This is an in line template. <br />
This is a #{tag} that can be accessed by the callback function
</ct:inline>
PHP/HTML: example.php
<?php
$current_dir = dirname(__FILE__).DIRECTORY_SEPARATOR;
require_once dirname($current_dir).DIRECTORY_SEPARATOR.'customtags.php';
$ct = new CustomTags(array(
'parse_on_shutdown' => true,
'tag_directory' => $current_dir.'tags'.DIRECTORY_SEPARATOR,
'sniff_for_buried_tags' => true
));
?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Oliver Lillie">
<!-- Date: 2010-07-10 -->
</head>
<body>
<ct:youtube id="wfI0Z6YJhL0" />
</body>
</html>
Custom Tag PHP Function: tags/youtube/tag.php:
function ct_youtube($tag)
{
return '<object id="'.$tag['attributes']->id.'" value="http://www.youtube.com/v/'.$tag['attributes']->id.'" /><param ......>';
}
Output:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Oliver Lillie">
<!-- Date: 2010-07-10 -->
</head>
<body>
<object id="wfI0Z6YJhL0" value="http://www.youtube.com/v/wfI0Z6YJhL0" /><param ......>
</body>
</html>
I'm not 100% sure how it will react to non-standard tags, but if it works, simpleHTMLDom will be perfect for this.
$html = str_get_html('....');
then something along the lines of ...
$element = $html->find('youtube',0 ); // Finds first element
// - use "foreach" loop for final version
$element->tag = 'object';
$element->value = "http://www.youtube.com/v/".$element->id;
$element->innertext= "<param ......>"
....
echo $html;
you get the drift.
The beauty of this approach would be that every specific extension could add its data in clean HTML notation <tagname attribute="value">, with even the possibility of adding sub-tags for structured info, instead of kludgy {placeholder}s and regexes and so on.
I have never tried this and I don't have the time to test this right now, but if you decide to give it a try, I'd be interested to know whether this way turned out to be useful.

Categories