Jarid Posted August 6, 2010 Share Posted August 6, 2010 I am using this php code <?php echo $_GET['CiFrame']; ?> to check the url for the variable CiFrame, this allows me to link to a page through my page containing the iframe. Here is my iframe code. <iframe name="CiFrame" width="727" height="805" src="<?php echo $_GET['CiFrame']; ?>" scrolling="auto" frameborder="0"></iframe> The problem is that if the url does not contain a variable the iframe will not open a page. How can i set a default variable if one is not provided? Thank You Link to comment https://forums.phpfreaks.com/topic/210004-how-can-i-set-a-default-variable-if-one-has-not-been-set-in-the-url/ Share on other sites More sharing options...
litebearer Posted August 6, 2010 Share Posted August 6, 2010 psuedo... if isset get var = passed value else var = default value Link to comment https://forums.phpfreaks.com/topic/210004-how-can-i-set-a-default-variable-if-one-has-not-been-set-in-the-url/#findComment-1096068 Share on other sites More sharing options...
Jarid Posted August 6, 2010 Author Share Posted August 6, 2010 I don't understand how to apply the code you provided. I set $Openme as the var. I still don't understand how to check the url for CiFrame or use a default value if CiFrame is not specified in the url. Here is what i tried next, however it did not work. Any ideas? <?php if (isset ($_GET['CiFrame'])) $Openme = 'CiFrame'; else $Openme = '/NonMembersFeatured.php'; ?> Iframe Code <iframe name="CiFrame" width="727" height="805" src="<?php $Openme ?>" scrolling="auto" frameborder="0"></iframe> Thank You Link to comment https://forums.phpfreaks.com/topic/210004-how-can-i-set-a-default-variable-if-one-has-not-been-set-in-the-url/#findComment-1096080 Share on other sites More sharing options...
will35010 Posted August 6, 2010 Share Posted August 6, 2010 I don't understand how to apply the code you provided. I set $Openme as the var. I still don't understand how to check the url for CiFrame or use a default value if CiFrame is not specified in the url. Here is what i tried next, however it did not work. Any ideas? <?php if (isset ($_GET['CiFrame'])) $Openme = 'CiFrame'; else $Openme = '/NonMembersFeatured.php'; ?> Iframe Code <iframe name="CiFrame" width="727" height="805" src="<?php $Openme ?>" scrolling="auto" frameborder="0"></iframe> Thank You that should be: <?php if (isset ($_GET['CiFrame'])) $Openme = $_GET['CiFrame']; else $Openme = '/NonMembersFeatured.php'; ?> Link to comment https://forums.phpfreaks.com/topic/210004-how-can-i-set-a-default-variable-if-one-has-not-been-set-in-the-url/#findComment-1096082 Share on other sites More sharing options...
Jarid Posted August 6, 2010 Author Share Posted August 6, 2010 I put <?php if (isset ($_GET['CiFrame'])) $Openme = $_GET['CiFrame']; else $Openme = '/NonMembersFeatured.php'; ?> In the body right above my iframe code <iframe name="CiFrame" width="727" height="805" src="<?php $Openme ?>" scrolling="auto" frameborder="0"></iframe> I uploaded the page to my server and opened it in my browser. The iframe did not open /NonMembersFeatured.php and when i right clicked and went to source code my iframe showed src="". Why is this not working? Link to comment https://forums.phpfreaks.com/topic/210004-how-can-i-set-a-default-variable-if-one-has-not-been-set-in-the-url/#findComment-1096088 Share on other sites More sharing options...
hiprakhar Posted August 6, 2010 Share Posted August 6, 2010 I put <?php if (isset ($_GET['CiFrame'])) $Openme = $_GET['CiFrame']; else $Openme = '/NonMembersFeatured.php'; ?> In the body right above my iframe code <iframe name="CiFrame" width="727" height="805" src="<?php $Openme ?>" scrolling="auto" frameborder="0"></iframe> I uploaded the page to my server and opened it in my browser. The iframe did not open /NonMembersFeatured.php and when i right clicked and went to source code my iframe showed src="". Why is this not working? Try: <iframe name="CiFrame" width="727" height="805" src="<?php echo isset ($_GET['CiFrame'])?$_GET['CiFrame']:'/NonMembersFeatured.php' ?>" scrolling="auto" frameborder="0"></iframe> do tell if that worked Link to comment https://forums.phpfreaks.com/topic/210004-how-can-i-set-a-default-variable-if-one-has-not-been-set-in-the-url/#findComment-1096095 Share on other sites More sharing options...
Jarid Posted August 6, 2010 Author Share Posted August 6, 2010 Thanks for the help hiprakhar your solution worked, now i just have to adapt it for a few more pages. Link to comment https://forums.phpfreaks.com/topic/210004-how-can-i-set-a-default-variable-if-one-has-not-been-set-in-the-url/#findComment-1096098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.