Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP ECHO not visible in source code of HTML page

Posted on 2014-10-14
12
Medium Priority
?
619 Views
Last Modified: 2014-10-25
This code works fine. II'm using Google maps and Google Places API and store the response in an array and echo it.
But what I don't get, why is the API response visible in the browser but it is NOT there when I view the source code of the page? When I view the source code I just see the divs.



<?php
				$bizArray = file_get_contents("https://maps.googleapis.com/maps/api/place/search/json?location=".$jsonLAT.",".$jsonLNG."&radius=".$searchRadius."&types=".$category."&sensor=false&key=".$api_key);
				$bizArray = json_decode($bizArray, true);
				//print_r($bizArray);
				foreach ($bizArray['results'] as $key => $value) {
					$place_id = $value['place_id'];
					$bizData = file_get_contents("https://maps.googleapis.com/maps/api/place/details/json?placeid=".$place_id."&sensor=false&key=".$api_key);
					$bizData = json_decode($bizData, true);
					$bizItem = $bizData['result'];
					//print_r($bizItem); continue;
					?>
					<li class="listItem" category="<?php echo $category;?>" placeid="<?php echo $place_id;?>">
					<span class="item_name"><?php echo $bizItem['name'];?></span> - <span class="item_area"><?php echo $bizItem['vicinity'];?></span><br />
					<div class="item_details" style="margin-top: 5px;">
					<?php
						if(isset($bizItem['website']) && $bizItem['website']!=""){ ?>
							<span class="data_detail website">Website: <?php echo $bizItem['website']; ?></span><br />
						<?php }
						if(isset($bizItem['url']) && $bizItem['url']!=""){ ?>
							<span class="data_detail url">Google Plus: <?php echo $bizItem['url']; ?></span><br />
						<?php }
						if(isset($bizItem['formatted_phone_number']) && $bizItem['formatted_phone_number']!=""){ ?>
							<span class="data_detail formatted_phone_number">Phone: <?php echo $bizItem['formatted_phone_number']; ?></span><br />
						<?php }
						if(isset($bizItem['opening_hours']) && !empty($bizItem['opening_hours'])){
							$opening_hours = $bizItem['opening_hours'];
							$html = '<div class="data_detail opening_hours">';
							if($opening_hours[open_now]) {
								$html .= '<span>Open Now: Yes</span><br />';
							}
							if($opening_hours['periods'] && !empty($opening_hours['periods'])) {
								if($opening_hours['periods'][0]['time']==0 && $opening_hours['periods'][0]['time']==0) {
									$html .= '<span>Time: Always Open</span><br />';
								} else {
									$timesArr = array();
									foreach($opening_hours['periods'] as $period) {
										$day; $opening; $closing; $time;
										$opening = str_split($period['open']['time']);
										$opening = $opening[0].$opening[1].":".$opening[2].$opening[3];
										$closing = str_split($period['close']['time']);
										$closing = $closing[0].$closing[1].":".$closing[2].$closing[3];
										$time = $opening."-".$closing;
										switch($period['open']['day']){
											case 0: $day = 'Sun'; break;
											case 1: $day = 'Mon'; break;
											case 2: $day = 'Tus'; break;
											case 3: $day = 'Wed'; break;
											case 4: $day = 'Thu'; break;
											case 5: $day = 'Fri'; break;
											case 6: $day = 'Sat'; break;
											default: $day = '';
										}
										array_push($timesArr, $day." ".$time);
									}
									$html .= '<span>Day/Time: '. implode(', ', $timesArr) .'</span><br />';
								}
							}
							$html .= '</div><br />';
							echo $html;
						}
						if(isset($bizItem['price_level']) && $bizItem['price_level']!=""){
							switch($bizItem['price_level']){
								case 0: $price_level = "Free"; break;
								case 1: $price_level = "Inexpensive"; break;
								case 2: $price_level = "Moderate"; break;
								case 3: $price_level = "Expensive"; break;
								case 4: $price_level = "Very Expensive"; break;
								default: $price_level = "";
							} ?>
							<span class="data_detail price_level">Price Level: <?php echo $price_level; ?></span><br />
						<?php }
						if(isset($bizItem['rating']) && $bizItem['rating']!=""){ ?>
							<span class="data_detail rating">Rating: <?php echo $bizItem['rating']; ?></span><br />
						<?php }
						if(isset($bizItem['aspects']) && !empty($bizItem['aspects'])){
							$aspectsArr = array();
							foreach($bizItem['aspects'] as $aspect) {
								array_push($aspectsArr, $aspect['type']." - ".$aspect['rating']);
							} ?>
							<span class="data_detail aspects">Rating Aspects: <?php echo implode(', ', $aspectsArr); ?></span><br />
						<?php }
						if(isset($bizItem['review_summary']) && $bizItem['review_summary']!=""){ ?>
							<span class="data_detail review_summary">Review Summary: <?php echo $bizItem['review_summary']; ?></span><br />
						<?php }
						if(isset($bizItem['reviews']) && !empty($bizItem['reviews'])){
							$html = '<div class="data_detail reviews"><span>Reviews: </span><br />';
							foreach($bizItem['reviews'] as $review) {
								$html .= '<div class="user_review">';
								$html .= '<span>'. (strtolower($review['author_name'])=='a google user' ? "Anonymous" : $review['author_name']).'</span><br />';
								if(isset($review['rating'])){
									$html .= '<span>Rating: '.$review['rating'].'</span><br />';
								}
								if(isset($review['aspects']) && !empty($review['aspects'])){
									$aspectsArr = array();
									foreach($review['aspects'] as $aspect) {
										array_push($aspectsArr, $aspect['type']." - ".$aspect['rating']);
									}
									$html .= '<span>Rating Aspects: '.implode(', ', $aspectsArr).'</span><br />';
								}
								if(isset($review['text']) && $review['text'] != ""){
									$html .= '<span>'.$review['text'].'</span><br />';
								}
								$html .= '</div>';
							}
							$html .= '</div><br />';
							echo $html;
						} ?>
					</div>
					</li>
				<?php }
				?>
				</ol>
			</div>
		<?php
		} ?>

Open in new window

0
Comment
Question by:seopti
  • 4
  • 4
  • 2
  • +2
12 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40380883
Copied the script verbatim and installed it here:
http://iconoun.com/demo/temp_seopti.php

Is there a URL we can use to see this effect, or can you please post a working script that demonstrates the phenomenon?
0
 

Author Comment

by:seopti
ID: 40380936
Thanks, yes it is:
http://www.local-health.net/california/banning/rachael-slomovic-31660.html

Please click on the tab "Nearby" and scroll down. There are three categories, Dentists, Doctors, Hospitals. The results for the businesses come from the Google Places API via JSON and I echo them with the code above. But it's a mystery for me why this is not visible in the source code of the browser.
0
 
LVL 61

Expert Comment

by:Julian Hansen
ID: 40380971
Can't see where you are echoing the output in the link provided?

What are we looking for?

Original code post - dumps of var's (print_r) were commented out.

Can you tell us specifically what you are seeing in the browser that you are not seeing in the source?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:seopti
ID: 40380986
Please go to this url:
http://www.local-health.net/california/banning/rachael-slomovic-31660.html

Click on the Nearby Tab and scrool down, you will find:
DENTISTS
1.    Beaumont Dental Group - 930 Beaumont Ave, Beaumont
...
DOCTORS
....

HOSPITALS
....

Now all this text (the businesses) from the Places API response is not visible in the browser source.
0
 

Author Comment

by:seopti
ID: 40380987
This is what I see in the browser source code:

<div id="poiListData">
					<div class="hidden" id="dentist_items">
				<div class="data_title">Dentists</div>
				<ol class="data_items">
								</ol>
			</div>
					<div class="hidden" id="doctor_items">
				<div class="data_title">Doctors</div>
				<ol class="data_items">
								</ol>
			</div>
					<div class="hidden" id="hospital_items">
				<div class="data_title">Hospitals</div>
				<ol class="data_items">
								</ol>
			</div>

Open in new window

0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 40380998
The response from google maps contains client-side scripts that modify the page after it loads. The source code for the page never changes, but the rendering of the page changes when the scripts are executed. The source code is always exactly what is delivered by the web server. You should, however, since you're inserting the returned script tag via php, be able to see that script tag in the page source code. But most of the google source code is collected and inserted after the page is loaded. Make sense?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40381009
This is probably loaded by an AJAX request.  You will not see it in the "view source" which is what the browser saw at the start of rendering the page.  It only appears after the background script injects something into the DOM.

This article shows the basics of jQuery and AJAX.  You can try these scripts and use "view source" to get a small test case that illustrates what is going on.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
0
 

Author Comment

by:seopti
ID: 40381015
Yes it is JSON and it is AJAX. I tried to store that JSON response in an array and output it. I think it's harder than I thought.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 40381020
At some level the JSON response should be a string of text.  You might try using it as if it were a string variable and not a JSON data type to see if that will reveal its secrets.
0
 
LVL 61

Expert Comment

by:Julian Hansen
ID: 40381540
I agree with the comments about AJAX loading of content - however I did a test with FF
Snippet of browser source below
 Banning health services with Zip Code 92220:<br>
<span style="line-height: 1.6em;">

<a href="/california/banning/john-alexander-63069.html">John Alexander</a>
	Alexander Dental Lab  <br>

			<a href="/california/banning/bakhtiar-ahmad-62451.html">Bakhtiar Ahmad</a>
	Bakhtiar Ahmad MD  <br>

			<a href="/california/banning/david-j-scanlan-64332.html">David J Scanlan</a>
	Banning Chiropractic  <br>

			<a href="/california/banning/471-n-san-gorgonio-ave-64333.html">Banning Dental Ctr</a>
	 <br>

			<a href="/california/banning/lisa-wilson-64334.html">Lisa Wilson</a>
	Banning Family Dentistry  <br>

			<a href="/california/banning/mario-bertumen-31658.html">Mario Bertumen</a>
	Banning Healthcare  <br>

			<a href="/california/banning/tiffany-holmes-64336.html">Tiffany Holmes</a>
	Banning Pediatric Clinic  <br>

			<a href="/california/banning/paul-nemeth-31659.html">Paul Nemeth</a>
	Banning Psychological Assoc  <br>

			<a href="/california/banning/264-n-highland-spgs-ave-5b-64362.html">Beaumont Dental Ctr</a>
	 <br>

			<a href="/california/banning/janna-redmond-64367.html">Janna Redmond</a>
	Beaver Medical Group  <br>

			<a href="/california/banning/celeste-lucas-65299.html">Celeste Lucas</a>
	Butterfield Dental  <br>

			<a href="/california/banning/anthony-lopez-31723.html">Anthony Lopez</a>
	Cherry Valley Health Care  <br>

			<a href="/california/banning/daniel-bessesen-64754.html">Daniel Bessesen</a>
	Daniel Bessesen MD  <br>

			<a href="/california/banning/6350-w-ramsey-st-a-64984.html">Dental Works</a>
	 <br>

			<a href="/california/banning/trudy-wright-65011.html">Trudy Wright</a>
	Desert Hematology Oncology  <br>

			<a href="/california/banning/joy-oliverio-67768.html">Joy Oliverio</a>
	Exciting Skin Laser Ctr  <br>

			<a href="/california/banning/norma-saucedo-67878.html">Norma Saucedo</a>
	Friendly OBGYN Medical Grp  <br>

			<a href="/california/banning/denise-frank-68031.html">Denise Frank</a>
	Gambro Healthcare  <br>

			<a href="/california/banning/john-cassar-31874.html">John Cassar</a>
	Golden Meadows  <br>

			<a href="/california/banning/nita-beloso-76245.html">Nita Beloso</a>
	Golden View Guest Home  <br>

			<a href="/california/banning/hank-lefler-76317.html">Hank Lefler</a>
	Haven Laboratory  <br>

			<a href="/california/banning/c-ane-padilla-76325.html">C Ane Padilla</a>
	Healing By Design  <br>

			<a href="/california/banning/264-n-highland-springs-1-d-76369.html">Hematology Oncology</a>
	 <br>

			<a href="/california/banning/3158-w-ramsey-st-76497.html">Indian Health Inc</a>
	 <br>

						</span><br><br>

Open in new window

0
 
LVL 45

Expert Comment

by:Chris Stanyon
ID: 40382427
Others have already hit the nail on the head - the AJAX injection doesn't change what you see when you 'View Source'.

If you're doing a lot of development work and need a more detailed look at what you're doing, consider using some of the web developer browser plugins. For example, the Web Developer plugin for Firefox adds a menu option that lets you view the 'Generated Source'. This would show you the source after the AJAX injection and you wouldn't have the problem.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40382448
@ChrisStanyon: Good call.  I think there may be some similar features available in Chrome Dev Tools.
https://developer.chrome.com/devtools
http://discover-devtools.codeschool.com/
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question