Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
dynamically changing the content of an iframe
Old 02-18-2011, 05:43 PM dynamically changing the content of an iframe
madnhain's Avatar
Experienced Talker

Posts: 42
Name: Jez
Location: Grand Junction, CO / Williston, ND
Trades: 0
This is part of a chat client I am working on where the content of an iframe is dependent on a pre-defined variable:

here is the code in it's entirety.
PHP Code:
<?php
session_start
();
include(
'../mylibrary/dcon.php');

if (!isset(
$_REQUEST['user'])){
    echo 
'you\'r not logged in!';
    exit;
}else{
    
$chatuser $_REQUEST['user'];
}

//Check DB for validity of user & get first name
$query "SELECT fname FROM customers WHERE email = '$chatuser'";
$result mysql_query($query);
$row mysql_fetch_array($resultMYSQL_ASSOC);

$chatuser $row[fname];                                                   //define chat user name

$stringData 'This is test info';                                           //enter test information

$filename $chatuser ."_"date('D M j').".html";                 //define file name
$chatfile fopen($filename'a+') or die('cant open file');     

fwrite($chatfile$stringData);                                             //write test info to file

echo    "<iframe src=\'$chatfile\' width=\'50%\' height=\'300\'>";
echo    
"<p>Your browser does not support iframes.</p></iframe>";


?>
everything seems to work fine, the file creates, gets some test data entered into it, but does not show up in the iFrame... any thoughts?

Last edited by madnhain; 02-18-2011 at 05:45 PM..
madnhain is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-18-2011, 07:54 PM Re: dynamically changing the content of an iframe
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
PHP Code:
echo    "<iframe src=\'$chatfile\' width=\'50%\' height=\'300\'>";
echo    
"<p>Your browser does not support iframes.</p></iframe>"
You don't have to do this since the quotes you are escaping are single quotes that are inside double quotes. If you used double quotes inside double quotes or single inside single then you would need escaping. Use this instead, it should work:

PHP Code:
echo    "<iframe src='$chatfile' width='50%' height='300'>";
echo    
"<p>Your browser does not support iframes.</p></iframe>"
__________________

Please login or register to view this content. Registration is FREE
Marik is offline
Reply With Quote
View Public Profile
 
Old 02-20-2011, 10:16 PM Re: dynamically changing the content of an iframe
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
And you should have an fclose before writing the iframe code. You should also be testing for no user found by the db query.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 02-21-2011, 03:26 AM Re: dynamically changing the content of an iframe
madnhain's Avatar
Experienced Talker

Posts: 42
Name: Jez
Location: Grand Junction, CO / Williston, ND
Trades: 0
Thank you for the suggestions... still no luck. If I put a second iframe in the code, it'll sometimes load the second iframe perfectly fine, but not the first... I've tried putting the iframe outside the php code, tried different browsers with different results. Fire Fox seems to not do too well with iFrames.... This really has me baffled.
madnhain is offline
Reply With Quote
View Public Profile
 
Old 02-21-2011, 04:17 AM Re: dynamically changing the content of an iframe
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I think the problem is here:
PHP Code:
echo    "<iframe src=\'$chatfile\' width=\'50%\' height=\'300\'>"
$chatfile is a file handle, not a string. The src attribute should be set to the url of the file.

PHP Code:
echo    "<iframe src='http://yoursite.com/$filename' width='50%' height='300'>"
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-21-2011, 10:39 AM Re: dynamically changing the content of an iframe
madnhain's Avatar
Experienced Talker

Posts: 42
Name: Jez
Location: Grand Junction, CO / Williston, ND
Trades: 0
Again, thank you all for your input! I believe I've found the problem, however I have no CLUE why this is happening.
here is my code currently (there's a lot of excessive experimental crap in it)
PHP Code:
<html>
<body>
<?php
session_start
();
include(
'../mylibrary/dcon.php');

if (!isset(
$_REQUEST['user'])){
    echo 
'you\'r not logged in!';
    exit;
}else{
    
$chatuser $_REQUEST['user'];
}

//Check DB for validity of user & get first name
$query "SELECT fname FROM customers WHERE email = '$chatuser'";
$result mysql_query($query);
$row mysql_fetch_array($resultMYSQL_ASSOC);

$chatuser $row[fname];
//chmod("index.php", 0600); //give this file permissions
$stringData 'This is test info\n';

$filename $chatuser ."_"date('D M j').".html";
$chatfile fopen($filename'a+') or die('cant open file');

fwrite($chatfile$stringData);

echo 
$chatuser.'<p>';     //Define first name as chatuser id
echo $chatfile;
fclose($chatfile);

echo 
"<br><IFRAME SRC=$chatfile WIDTH=450 HEIGHT=100></IFRAME><br>";

echo  
"<iframe src='http://testarea.net78.net/chat/$chatfile' width='50%' height='300'></IFRAME><br>";
?>

<IFRAME SRC="<? $chatfile ?>" WIDTH=450 HEIGHT=100>
</IFRAME>

</body>
</html>
the
PHP Code:
echo $chatfile
results in:

Resource id #9

my understanding is that is usually a mysql related error? So it's $chatfile is not producing a file name....
madnhain is offline
Reply With Quote
View Public Profile
 
Old 02-21-2011, 11:00 AM Re: dynamically changing the content of an iframe
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Read the documentation for fopen. It returns a resource not a string. You need to determine the URL of the file and use that for the src attribute.

Also, do not use short tags (<? or <?=). Your script may work on your server but if you were to put it on another server where short tags are disable you would get an error. Even if you don't intend for your script to be portable, using them is a bad habit. Eventually they will be removed from PHP entirely.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-21-2011, 12:52 PM Re: dynamically changing the content of an iframe
madnhain's Avatar
Experienced Talker

Posts: 42
Name: Jez
Location: Grand Junction, CO / Williston, ND
Trades: 0
I agree NullPointer (with the short tags thing) I normally don't use them, but that was a frustrated attempt at making something happen.

Good call on the resource! you were absolutely correct, I solved that issue by"
PHP Code:

$literal_file 
basename($filename);

fclose($chatfile);

echo 
$literal_file;

echo 
"<br><IFRAME SRC='$literal_file' WIDTH='450' HEIGHT='100'></IFRAME><br>";

echo  
"<IFRAME SRC='http://testarea.net78.net/chat/Jez_Mon Feb 21.html' width='50%' height='300'></IFRAME><br>";
?>

<IFRAME SRC="http://testarea.net78.net/chat/Jez_Mon Feb 21.html" WIDTH=450 HEIGHT=100>
</IFRAME>

</body>
</html> 
good 'ol basename()

Now I'm banging my head on the wall AGAIN because it's STILL not wanting to insert the specified file into the iframe. I can call http://testarea.net78.net/chat/Jez_Mon%20Feb%2021.html directly from the browser, but as soon as I use it as a src in the iframe... nothing. Uhg!

As you can see, I put the literal URL into the iframe (just to see...) and nothing.

There must be something stupidly obvious that I'm overlooking here.

even the iframe outside of the php isn't working...
madnhain is offline
Reply With Quote
View Public Profile
 
Old 02-21-2011, 07:50 PM Re: dynamically changing the content of an iframe
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You need to encode the file name:
http://us2.php.net/manual/en/function.urlencode.php
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-21-2011, 08:11 PM Re: dynamically changing the content of an iframe
madnhain's Avatar
Experienced Talker

Posts: 42
Name: Jez
Location: Grand Junction, CO / Williston, ND
Trades: 0
Ok, I went to run some errands, and came back, reloaded the page that's been giving me grief, and suddenly it works.....

Sooo.... what the heck?!
madnhain is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to dynamically changing the content of an iframe
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30632 seconds with 12 queries