<DIV> shows 3 images instead of 1 - php

I am new to the community, and this is my first question so far.
I got stuck an hour ago on this. Session checks if user is logged in or not then displays either login-form_eng.php or logout-form_eng.php with include. Problem is the image shown is displayed 3 times and I am only calling the include function once.
<body>
<div id="full-wrap" class="container-wrap">
<div id="header-wrap" class="secondary-wrap">
<h1 class="linky-logo" title="elcoma.com"></h1>
<div id="main-menu-wrap" class="secondary-wrap">
<table border="0"cellspacing="0"cellpadding="0">
<tr><td>
<a class="linky8"title="Home"onclick="alert('Button Click')">
</td><td>
<a class="linky2"title="News"onclick="alert('Button Click')">
</td><td>
<a class="linky3"title="Products"onclick="alert('Button Click')">
</td><td>
<a class="linky4"title="Services"onclick="alert('Button Click')">
</td><td>
<a class="linky5"title="About Us"onclick="alert('Button Click')">
</td><td>
<a class="linky6"title="Contact"onclick="alert('Button Click')">
</td>
</tr>
</table>
</div>
</div>
<div id="login-logoff-wrap" class="secondary-wrap">
<?php
session_start();
if(isset($_SESSION['user']))
{
echo "Welcome back ". $_SESSION['user']. ". Please enjoy your stay at our site!";
include "logout-form_eng.php";
} else {
echo "Welcome guest. Please log in or register at our site";
include "login-form_eng.php";
}
?>
</div>
</div>
Here is a link to how the problem looks like:
Picture
EDIT
Apparently the two divs around the php script were causing the problem. But I still can't explain why, can somebody explain it to me?
I removed all classes out of all divs one by one then I started deleting the divs. That's how I came to the solution that the two divs around the php login script were somehow "calling" the script? I have no other explanation and I would appreciate a valid one. Thank you!

session_start() should go before all output on the page. The HTML you have preceeding the PHP is considered output.
Since you didn't post the PHP for your two PHP pages, is it possible that there is a redirect in one of these pages that loops back on itself?
Also use include_once() to prevent the page from being included multiple times.
http://php.net/manual/en/function.include-once.php

Check your CSS. Class secondary-wrap is used three times in the DOM. I suppose, that in your CSS the image is used as background in .secondary-wrap.
To solve this, you could stick additional class, say .my-picture to the topmost <div>:
<div id="header-wrap" class="secondary-wrap my-picture">
and move the background image from .secondary-wrap to new .my-picture.
Or just remove class="secondary-wrap" from the two other divs:
<div id="main-menu-wrap" class="secondary-wrap">
and
<div id="login-logoff-wrap" class="secondary-wrap">
if there's no other relevant CSS in this class.

Related

PHP - using include, can i execute on a different div in the page?

I have a small problem, and I'll try to break it down into a smaller one so I can explain it properly.
I'm working on a web application and I have a couple of divs, such as this:
<div class="1">
//search bar
</div>
<div class="2">
include_once 'actioncontroller.php';
</div>
<div class="3">
</div>
In the actioncontroller.php I'm having an action controller which decides what action to take depending on what's pressed on the page. I've put it in the second div because ultimately that's where I want to print everything.
My question is, is there any way that I can use the code from the second div in the first one, without it printing it there? Basically I want the search bar from div one to do/print the same thing as the one in div 2 does, but I know(think) that PHP can't see code above the include_once, and if I include the actioncontroller.php in the first div it will print it there, instead of printing it in the second one, as I want.
Hope I was clear enough, it's not a problem of coding, it's just a matter of how can I read the script in the first div and then run it in the second one...
Thanks in advance
My question is, is there any way that I can use the code from the second div in the first one, without it printing it there?
Yes, but the best solution is to change the code you've already written. In the long-term, it is vitally important that you minimize your "procedural" PHP code, so that nothing ever happens simply by include/require-ing a file.
Trust me on this, it works for toy project, but it always leads to insanity and pain in the end. For example, don't put this in a file:
<?php
echo("Header section");
This is bad because you have no choice about when it prints. This is a step up:
<?php
function WriteHeader(){
echo("Header section");
}
Even better would be to use classes an autoloading, but that's probably more than you need to hear right now. With that kind of approach, your main page would look more like:
<?php
// This next line simply makes the class ActionController *available*,
// it does NOT cause new things to happen on its own
include_once("actioncontroller.php");
?>
<div class="1">
<?= ActionController::MakeSomeHTML(); ?>
</div>
<div class="2">
<?= ActionController::MakeSomeHTML(); ?>
</div>
<div class="3">
</div>
This code takes the output of actioncontroller.php and saves it into a variable, which can be echo'd multiple times.
<?php
ob_start();
include_once 'actioncontroller.php';
$output = ob_get_contents();
ob_end_clean();
?>
<div class="1">
<?php echo $output; ?>
</div>
<div class="2">
<?php echo $output; ?>
</div>

Open links placed in different divs in one div with php

I've been looking at this for a few hours now and I've probably overlooked something silly, but I really can't get this to work.
I have created a .php file with four different php-files which are included with the
I am practicing with building websites and my first website used to solve this problem with frames, I could simply target every anchor tag to the mainframe and it worked perfectly. However, as frames are a deprecated feature, I decided to replace them. I can't seem to get the links working however.
There are tons of answers around, and that's probably the biggest problem, I can't figure out which solution fits to my specific design. Sorry if this is a doublepost.
This is what I've created so far:
<div id="header" class="header">
<img src="Images/metallic.png" width="125" height="125" alt=""/>
<img src="Images/database.png" width="85%" height="125" align="right" alt=""/>
</div>
<?php include 'Parts/upperdivs.php'; ?>
<?php include 'Parts/navigation.php'; ?>
<?php include 'Pages/main.php'; ?>
As said, there are buttons with hyperlinks in the navigation page and 'normal' hyperlinks in the upperdivs. Is there a way to open all those hyperlinks in the main content div, without having to copy all I've already got? I've read a lot of information about Ajax and the PHP-load feature, but I'm not sure what I should use. I've tried adding it as well, but couldn't get it to work. Thanks in advance!
Edit: I've also tried using an Iframe with an Iframe ID, and pointing to it using the target-tag. The problem is that the pages differ very much in content - if I set the height of the Iframe to, let's say, 1000px, it's way to large and you can scroll too far down on pages with minimal content, and if I set it to 100px, I get two scrollbars, one on the Iframe and one on the right side of the webpage, which is very ugly - and above all - very annoying.
Without being clear on exactly what you're asking, I assume you're looking for an easier way to handle includes.
This is not the best way to do it, but I would have each page be in the URL you want, and have the 'Parts' pages be in a separate folder.
/
| main.php
| about.php
| news.php
/ Parts
| navigation.php
| upperdivs.php
| EVERY_PAGE.php
Then as a shortcut, you could make EVERY_PAGE.php like this:
<div id="header" class="header">
<img src="Images/metallic.png" width="125" height="125" alt=""/>
<img src="Images/database.png" width="85%" height="125" align="right" alt=""/>
</div>
<?php include 'Parts/upperdivs.php'; ?>
<?php include 'Parts/navigation.php'; ?>
On each page you would do this:
<?php include 'Parts/EVERY_PAGE.php'; ?>
///
// ... Page code here ...
//
Also, it's good to learn some better styles of coding, but this will get the job done in a clean and quick way.

Variable scoping across <?php ...?> blocks with HTML interspersed

I am very new to webscripting and technologies. So please pardon me if this is a very basic query. Further I have been researching this all day and I haven't been able to figure out why this is not working.
I am essentially trying to improve a website for my wife. The design dictates that we have a common header.php file that can be included into the various static pages that the website contains.
Now as a new requirement, they want to target a few static pages targeting different keywords, and for this the company wants to setup a different "Heading Message". So I want to dynamically pass a different "$page_heading" before I include my header.php.
My header.php has a bunch of HTML code with interspersed in between , so the following doesn't seem to be working:
In <mypage.php>:
...
<body>
<div class="container">
<?php
//global page_header;
$page_header = 'A Wildlife Resort of South India';
include('header.php');
?>
...
In <header.php>:
<header class="row-fluid">
<div class="header-main">
<img src="http://www.innthewild.com/img/itw-logo.png" alt="Inn The Wild" style="margin-top:8px;"/>
<div class="pull-right" style="height: 20px;">
<nav>
...
<div class="heading pull-right">
<?php
if(!isset($page_heading)) {
$page_heading = 'A Wilderness Retreat — Masinagudi Jungle Resort, India';
}
echo $page_heading;
?>
</div>
...
The above seems like it should work straight up, but the variable seems to be losing its scope across a new instance. How do I make this work?
Here are the example pages: http://www.innthewild.com and http://innthewild.com/resorts-places-around-bangalore.php
You're calling it $page_header in mypage.php and $page_heading in header.php.
Change one or the the other so that the variable name matches across them
u don't need to pass it
$some_var = "text";
include "some.php";
the script you just included can access the $some_var

Get specific html content from other site with PHP

I want to try and get the latest movie I checked on the IcheckMovies site and display it on my website. I don't know how, I've read about php_get_contents() and then getting an element but the specific element I want is rather deep in the DOM-structure. Its in a div in a div in a list in a ...
So, this is the link I want to get my content from: http://www.icheckmovies.com/profiles/robinwatchesmovies and I want to get the first title of the movie in the list.
Thanks so much in advance!
EDIT:
So using the file_get_contents() method
<?php
$html = file_get_contents('http://www.icheckmovies.com/profiles/robinwatchesmovies/');
echo $html;
?>
I got this html output. Now, I just need to get 'Smashed' so the content of the href link inside the h3 inside a div inside a div inside a list. This is where I don't know how to get it.
...
<div class="span-7">
<h2>Checks</h2>
<ol class="itemList">
<li class="listItem listItemSmall listItemMovie movie">
<div class="listImage listImageCover">
<a class="dvdCoverSmall" title="View detailed information on Smashed (2012)" href="/movies/smashed/"></a>
<div class="coverImage" style="background: url(/var/covers/small/10/1097928.jpg);"></div>
</div>
<h3>
<a title="View detailed information on Smashed (2012)" href="/movies/smashed/">Smashed</a>
</h3>
<span class="info">6 days ago</span>
</li>
<li class="listItem listItemSmall listItemMovie movie">
<li class="listItem listItemSmall listItemMovie movie">
</ol>
<span>
</div>
...
There are some libraries which could help you!
One I've used for the same purpose, a long time ago, is this: http://simplehtmldom.sourceforge.net/
I hope it help you!
follow steps to achieve this
STEP1:-
First get the contents using file_get_contents in a php file
ex: getcontent.php
<?php
echo file_get_contents("http://www.icheckmovies.com/movies/checked/?user=robinwatchesmovies ");
?>
STEP2:-
CALL the above script using ajax call and add the content to a visibility hidden field in the html.
ex:
$('#hidden_div').html(response);
html:-
<html>
<body>
<div id='hidden_div' style='visibility:hidden'>
</div>
</body>
</html>
STEP3:-
now extract the id what ever you want.
What you are asking for is called as web scraping ,I have done this a few months back, the process goes like this,
Make a HttpRequest to the site from which you need the content,check
the php class for it
Use a DOM parse library for handling the downloaded page (it would be in html),simple HTLM DOM would be a good choice
Extract your required information
Here are some tutorials for you,
HTML Parsing and Screen Scraping with the Simple HTML DOM
Library
Beginning web page scraping with php
SO Posts:
HTML Scraping in Php
And best of all Google is your friend just search for "PHP scraping"

All the sudden my links not working in php

I have a page where all links where working properly but all the sudden some links are not working anymore.
I am puzzling myself to undersand why. Nothing really changed. Maybe some css details.
Is there anyone who can give a clue?
Thank you for any help. me abou twhat might have happened.
Francesco
PS sorry forgot to say that looking at the source code the links are there and they work. In design view they just do nothing. They look like normal text.
<div id="centrale"><h1> Upcoming events</h1>
<div class="centrale_event">CLICK HERE TO SEE ALL UPCOMING EVENTS</div>
<p class="line"> </p>
<?php do { ?>
<div class="centrale_event">
<p><img src="<?php echo 'drawings/'.$row_rstevents['event_picture']; ?>" class="float" alt="" /><span class="big"><?php echo $row_rstevents['event_title']; ?></span></p>
<p><strong><em>Starting on <?php echo $row_rstevents['date']; ?></em></strong></p>
<p><strong>Where</strong>: <?php echo $row_rstevents['event_town']; ?></p>
<p><strong>Place</strong>: <?php echo $row_rstevents['place']; ?></p>
<p><?php echo extractFirst($row_rstevents['event_details']); ?> MORE INFO HERE</p>
<p class="line"> </p>
</div>
<?php } while ($row_rstevents = mysql_fetch_assoc($rstevents)); ?>
<div class="centrale_event"><p>CLICK HERE TO SEE ALL UPCOMING EVENTS</p></div>
</div>
Are you using Dreamweaver? I thought you might seeing as you mentioned Design View.. If that's the case then just hit F12 to view in a browser, the design view of DW is pretty lame.
Nothing to do with the link problem, but is there a reason you're using a do {} while () loop to output your database results? Using this construct will output at least one blank event before any actual data shows up, as the first time around the loop, you haven't retrieved any data from the query yet. Any reason you can't do a regular while() { } loop?

Categories