PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun May 28, 2017 11:22 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu Mar 16, 2017 10:36 am 
Offline
Forum Commoner

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 94
This is my latest shortened version of the homepage in my reg-login site php.
When you login to your account, your homepage welcomes yuo with your first & surname.
Then it is supposed to show you your bio ($row "bio" in tbl) and show you a url in an iframe ($row "your website" in tbl).

Problem is, the iframe is not showing the data (url) that is in the "your website" in tbl.
I tried escaping, switching to single quote from double but no luck.
What do you think is wrong ?

Syntax: [ Download ] [ Hide ]
<html>
<head>
<title>
$user Home Page
</title>
</head>
<body>
<body background=".png">

<?php
session_start&#40;&#41;;
require "conn.php";

/*Check if user is logged-in or not by checking if session is set or not.
If user is not logged-in then redirect to login page. Else, show user&#39;s account homepage.php.*/


if&#40;!isset&#40;$_SESSION["user"]&#41;&#41;
{
    header&#40;"location:login.php"&#41;;
}
else
{
    $user = $_SESSION["user"];
    $sql = "SELECT * FROM users WHERE Username = &#39;".$user."&#39;";
    $result = $conn->query&#40;$sql&#41;;
   while&#40;$row = $result->fetch_assoc&#40;&#41;&#41;
        {
            $db_id = $row["Id"];
            $db_username = $row["Username"];
            $db_forename = $row["Forename"];
            $db_surname = $row["Surname"];
            $db_email = $row["Email"];
            $db_bio = $row["Bio"];
            $db_your_fav_url = $row["Fav_Url"];
   
       
            //Welcome user by name.
                echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

                <?php
                //Display log-out link.
                echo "<p align=&#39;right&#39;><a href=&#39;logout.php&#39;>$user Log Out</a>";?>|</p><br>
       
        <?php
                //Display User Bio.  
                echo "<br><b>Bio:</b><br>
                $db_bio"
;?><br>
                <br>
               
                <?php
                //Display User&#39;s Fav Url in iFrame.?>
                <iframe src=&#39;$db_your_fav_url&#39;></iframe>
                <?php                  
        }
}
?>

</body>
</html>


The "Bio" column shows no data on page even thopugh the column contains data in the db.
I get error:

[16-Mar-2017 15:29:44 UTC] PHP Notice: Undefined index: Your_Fav_Url in /home/sn/public_html/sn/home.php on line 34


Top
 Profile  
 
PostPosted: Thu Mar 16, 2017 10:42 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6243
Location: Montreal, Canada
Your code and the notice do not match. Your code shows you looking for index 'Fav_Url' while the notice complains about 'Your_Fav_Url' not being defined.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 5:32 pm 
Offline
Forum Commoner

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 94
Celauran wrote:
Your code and the notice do not match. Your code shows you looking for index 'Fav_Url' while the notice complains about 'Your_Fav_Url' not being defined.



Notice do not match cos I actually edited the code and notice before posting in this thread. I changed my actual mysql column name to another when posting in this thread because the name of the mysql column would've let you scratching your head.
Anyway, I got pointed-out that the reason why the variable value (url) was not showing up on the iframe was due to the php tags missing. Check my code inside the iframe tags, you will see the url of the iframe is a php variable without the php tags. That was my error.


Top
 Profile  
 
PostPosted: Fri Mar 17, 2017 8:47 pm 
Offline
Forum Commoner

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 94
Here is latest update of the code but still it shows not the variable value as the iframe url. Variable calls db row data.
iFrame supposed to open to the url mentioned in the variable. The variable gets the data from the db row: Latest_View.
I get no errors, though!

Syntax: [ Download ] [ Hide ]
<html>
<head>
<title>
<?php
$user Home Page
?>
</title>
</head>
<body>
<body background=".png">

<?php
session_start&#40;&#41;;
require "conn.php";

/*Check if user is logged-in or not by checking if session is set or not.
If user is not logged-in then redirect to login page. Else, show user&#39;s account homepage.*/


if&#40;!isset&#40;$_SESSION["user"]&#41;&#41;
{
    header&#40;"location:login.php"&#41;;
}
else
{
    $user = $_SESSION["user"];
    $sql = "SELECT * FROM $user WHERE Username = &#39;".$user."&#39;";
    $result = $conn->query&#40;$sql&#41;;
   while&#40;$row = $result->fetch_assoc&#40;&#41;&#41;
        {
            $db_id = $row["Id"];
            $db_username = $row["Username"];
            $db_forename = $row["Forename"];
            $db_surname = $row["Surname"];
            $db_email = $row["Email"];
            $db_bio = $row["Bio"];
                $db_latest_view = $row["Latest_View"];
   
       
            //Welcome user by name.
                echo "<center>Welcome <b><h2>$db_forename $db_surname!</center>"?></h2></b>|

                <?php
                //Display log-out link.
                echo "<p align=&#39;right&#39;><a href=&#39;logout.php&#39;>$user Log Out</a>";?>|</p><br>
       
        <?php
                //Display User Bio.
                echo "<br><b>Bio:</b><br>";
                echo "$db_bio";?><br>
                <br>
               
                <?php
                //Display User&#39;s Latest View.
                echo "<br><b>Latest View:</b><br>";
                echo "$db_latest_view";?><br>
                <br>

                <?php
                //Display User&#39;s Latest Viewed Url in iFrame.?>
                <iframe src="<?php $db_latest_view;?>"></iframe>
                <?php                  
        }
}
?>

</body>
</html>


Top
 Profile  
 
PostPosted: Sat Mar 18, 2017 2:18 am 
Offline
Forum Contributor

Joined: Fri Jul 20, 2007 11:29 am
Posts: 324
<iframe src="<?php $db_latest_view;?>"></iframe>

<?php $db_latest_view;?>

That does nothing

You have to ECHO strings.

<?php echo $db_latest_view;?>

or

<?=$db_latest_view?>

_________________
Warning: I have no idea what I'm talking about.


Top
 Profile  
 
PostPosted: Sat Mar 18, 2017 2:21 pm 
Offline
Forum Contributor

Joined: Fri Jul 20, 2007 11:29 am
Posts: 324
http://php.net/echo

_________________
Warning: I have no idea what I'm talking about.


Top
 Profile  
 
PostPosted: Sat Mar 18, 2017 4:01 pm 
Offline
Forum Commoner

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 94
I'm afraid still did not work.
Url in db is valid:
https://www.youtube.com/playlist?list=P ... zUgYg_yG-U

I tried:
<iframe src="<?php echo $db_latest_view;?>">
<iframe src="<?php echo "$db_latest_view";?>">
<iframe src="<?php echo \"$db_latest_view\";?>">
<iframe src="<?=$db_latest_view?>">

But no luck! I think the 3rd one is invalid but still tried.


Top
 Profile  
 
PostPosted: Sat Mar 18, 2017 5:20 pm 
Offline
Forum Contributor

Joined: Fri Jul 20, 2007 11:29 am
Posts: 324
At this point you need to remove all code not directly related to the problem.

Remove all other html.

Remove session stuff.

Remove all other db row stuff.

Just connect to the database, fetch that 1 field from that 1 row.

Echo the url by itself.

Show the iframe tag with the echoed url.

_________________
Warning: I have no idea what I'm talking about.


Top
 Profile  
 
PostPosted: Sat Mar 18, 2017 7:28 pm 
Offline
Forum Commoner

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 94
I can try this techniq tonight. In the meanwhile good night or good morning! It is sunrising now.


Top
 Profile  
 
PostPosted: Sun Mar 19, 2017 8:26 am 
Offline
Forum Commoner

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 94
thinsoldier wrote:
At this point you need to remove all code not directly related to the problem.

Remove all other html.

Remove session stuff.

Remove all other db row stuff.

Just connect to the database, fetch that 1 field from that 1 row.

Echo the url by itself.

Show the iframe tag with the echoed url.




I tookout everything and left the page with only the following but I do not see any iframe today. Google Chrome.



<html>
<head>
<title>iframe</title>
</head>
<body>
<iframe src="http://www.google.com"></iframe>
<br>
<iframe src='http://www.google.com'></iframe>
<br>
</body>
</html>

I checked following and I can see on the right part of page the iframe has opened a page. That means iframe supported and working on my google chrome.
https://www.w3schools.com/tags/tryit.as ... tml_iframe

However, the leftside of the page shows:

<!DOCTYPE html>
<html>
<body>

<iframe src="https://www.w3schools.com">
<p>Your browser does not support iframes.</p>
</iframe>

</body>
</html>


Top
 Profile  
 
PostPosted: Sun Mar 19, 2017 3:03 pm 
Offline
Forum Contributor

Joined: Fri Jul 20, 2007 11:29 am
Posts: 324
Modern browsers respect the X-FRAME-OPTIONS header, that can have two values:

DENY – prevents the page from being rendered if it is contained in a frame
SAMEORIGIN – same as above, unless the page belongs to the same domain as the top-level frameset holder.

Users include Google, that cannot be embedded in a frame.

Browsers that support the header, with the minimum version:

IE8 and IE9
Opera 10.50
Safari 4
Chrome 4.1.249.1042
Firefox 3.6.9 (older versions with NoScript)

Some sites use CSP (Content Security Policy), which is a standard. The following header will prevent the document from loading in a frame anywhere:

Content-Security-Policy: frame-ancestors 'none'

http://stackoverflow.com/questions/2896 ... -of-iframe

Whenever possible try to link to live demo of what you're talking about: http://jsbin.com/kezakiyono/edit?html,output

_________________
Warning: I have no idea what I'm talking about.


Top
 Profile  
 
PostPosted: Sat May 06, 2017 8:31 am 
Offline
Forum Commoner

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 94
Man,

Atleast one url should load properly in my inframe since not every website in the world would be putting measures to foil iframes. 
How-about you try loading a page and when it works then give me the url to check out on my end.

I've now taken out all the session code altogether.
Code now looks like this:

Code:

<html>
<head>
<title>
Home Page
</title>
</head>
<body>
<body background=".png">

<?php
include 'config.php';

    $sql = "SELECT * FROM users WHERE usernames = 'USERNAME WENT HERE'";
    $result = mysqli_query($conn,$sql);
    $numrows = mysqli_num_rows($result);
    if($numrows >0)
    {    
        while ($row = mysqli_fetch_assoc($result))
        {
            $db_id = $row["ids"];
            $db_username = $row["usernames"];
            $db_first_name = $row["first_names"];
            $db_surname = $row["surnames"];
            $db_email = $row["emails"];
            $db_blog_url = $row["blogs_urls"];
    
            //Welcome user by name.
            echo "Welcome <b><h2>$db_first_name $db_surname!"?></h2></b>|

            <?php 
            //Display User's own blog Page in iframe.?>
            <iframe src='<?php echo $row["blog_urls"];?>'></iframe>
            <br>

            <?php 
            //Display 1st User's blog Page (regardless of who the user is) in iframe.?>
            <iframe src="<?php echo '.$blogs_urls[0].';?>"></iframe>
                
            <?php 
            //Display 1st User's blog Page (regardless of who the user is) in iframe.?>
            <iframe src='<?php echo ".$blogs_urls[0].";?>'></iframe>
            <?php 
            
        }
    }
    else
    {
    echo "<p>No Results!</p>\n" ;
    }    
?>

</body>
</html>



I have changed the url from my db to:

http://www.goviralnow.net/traffic-generation-techniques-for-2017/

But I don't see any pages loading. I picked a page most likely to be unknown. However, now see no blank page but 3 iframes with 3 error messages:

1st error message:

**Access forbidden!**

**You don't have permission to access the requested object. It is either read-protected or not readable by the server.**

**If you think this is a server error, please contact the webmaster.**

**Error 403**

**localhost**
**Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9**


2nd error message:

**Object not found!**

**The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.**

**If you think this is a server error, please contact the webmaster.**

**Error 404**

**localhost**
**Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9**


3rd error message:

Same as 1st error message.

Note from my most recent code, I have 3 iframes coding 3 different ways with php. Looking at these error messages and my 3 iframe codes, what is your conclusion ? What do you make out of all this ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group