|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Calling some html/css text within PHP
Hi -
(One of those 'new to it all' posts I'm afraid!) I want to have a page display some text if a condition is met within some PHP code. EG: <?php if something happens do this else display a few lines of text exit; ?> I'm sure its very basic but I can't seem to find how to do it. The text will be formatted in CSS styles (there's a link to the stylesheet in the file), and also needs to include links - I've included the sort of thing I want to have in the few lines of text at the bottom of this post. I suppose the question is "How do I include this sort of HTML in a PHP statement. " Excuse my ignorance... <p class="normal">I'm sorry, this page is restricted to members only. If you are a member already you are not currently logged into the forum. You can do so by </p> <p align="center" class="normal"><a href="http://www.mysite.info/fora/index.php?s=0&act=Login&CODE=00">clicking here</a></p> <p align="center" class="normal">If you are not a member, please click your browser back button to return to your previous page, or</p> <p align="center" class="normal"> <a href="http://www.mysite.info/fora/index.php?act=Reg&CODE=00">here to register</a> </p> <p align="center" class="normal">as a member. Registration is a free and simple process! <br> </p> |
|
#2
|
||||
|
||||
|
you can embed your php in your html like this
<? if(condition is true){ ?> html goes here <? } else { ?> html goes here <? } ?> |
|
#3
|
|||
|
|||
|
Hi
You can do what pprince said or you could use switch(); ! F! |
|
#4
|
|||
|
|||
|
Thanks both -
I should maybe have given the code in the beginning. The php statement is actually quite complicated (well for me anyway), with squiggly brackets tying it all together. Is it still feasible to break it down into a number of <?php and ?> bits? Its the 'not allowed here' echo that I want to replace with the previously mentioned text: <?php include("ibf.inc.php"); function protect($groups) { global $ibforums; $allowed=false; $newgroups=split(",",$groups); foreach($newgroups as $value) { phpif($value==$ibforums->member['mgroup']) { $allowed=true; } } if ($allowed==false) { //you can edit this to add code to do what you want if no access is allowed //echo "not allowed here"; header("Location: http://www.foundation-stage.info/forums/apology.htm"); exit(); |
|
#5
|
||||
|
||||
|
<?php
include("ibf.inc.php"); function protect($groups) { global $ibforums; $allowed=false; $newgroups=split(",",$groups); foreach($newgroups as $value) { phpif($value==$ibforums->member['mgroup']) { $allowed=true; } } if ($allowed==false) { //you can edit this to add code to do what you want if no access is allowed ?> <p class="normal">I'm sorry, this page is restricted to members only. If you are a member already you are not currently logged into the forum. You can do so by </p> <p align="center" class="normal"><a href="http://www.mysite.info/fora/index.php?s=0&act=Login&CODE=00">clicking here</a></p> <p align="center" class="normal">If you are not a member, please click your browser back button to return to your previous page, or</p> <p align="center" class="normal"> <a href="http://www.mysite.info/fora/index.php?act=Reg&CODE=00">here to register</a> </p> <p align="center" class="normal">as a member. Registration is a free and simple process! <br> </p> <? header("Location: http://www.foundation-stage.info/forums/apology.htm"); exit(); ?> |
|
#6
|
|||
|
|||
|
Sorry pprince - if you can have patience I'd really appreciate it. I sent you some bad code that I'd messed about with by mistake. The correct code is below - it has more squiggly brackets wrapping around the HTML bit, which is what is confusing me - I don't see how to separate the HTML outside two bits of PHP if you see what I mean...
Here's the code - I need to put the HTML into the commented and Echo bit: <?php include("ibf.inc.php"); function protect($groups) { global $ibforums; $allowed=false; $newgroups=split(",",$groups); foreach($newgroups as $value) { if($value==$ibforums->member['mgroup']) { $allowed=true; } } if ($allowed==false) { //you can edit this to add code to do what you want if no access is allowed echo "Not allowed Access"; exit(); } } ?> |
|
#7
|
|||
|
|||
|
Using include?
I also just tried to use include (replacing the echo line, and putting all the text in a separate file - the browser shows:
Warning: Failed opening 'apology.htm' for inclusion (include_path='.:/usr/share/pear') in /home/foundation/public_html/forums/protection.inc.php on line 16 Don't understand why I can't insert an include statement here and why it gives the /usr/share/pear path when earlier in the same script it uses include - all files are in the same directory. Excuse my ignorance... |
|
#8
|
||||
|
||||
|
email your full code
|
|
#9
|
|||
|
|||
|
Hi pprince -
Did you get the email? |
|
#10
|
||||
|
||||
|
nah, where did u send it?
|
|
#11
|
|||
|
|||
|
I just used this Devshed system.
|
|
#12
|
||||
|
||||
|
|
|
#13
|
|||
|
|||
|
Hi Paul -
Many thanks for your email and the fixed code - you're a splendid chap! Regards, Steve. |
|
#14
|
||||
|
||||
|
Steve,
post the answer for others to use Paul |
|
#15
|
|||
|
|||
|
Whoops, of course. This is/are the solution to the query I originally posted:
-------------------------------------- ok, this can be done in 1 of 2 ways 1. don't embed HTML, use only PHP to echo HTML 2. embed HTML in your PHP by opening and closing <? ?> You want me to explain the latter and its very simple. As you know a <? or <?php opens a PHP session and likewise a ?> closes a PHP session within a script. You can do this as many times as you like aslong as you follow 2 simple rules 1. Anything outside <? and ?> must conform to standard HTML code 2. Anything within must be PHP code The beauty of it is you can get the same effect using entirely PHP or just open PHP sessions as necessary within your HTML so, your code. to have standard HTML where you say just do this, I've commented where PHP opens and closes. Don't worry about If statements spanning HTML <?php //open PHP include("ibf.inc.php"); function protect($groups) { global $ibforums; $allowed=false; $newgroups=split(",",$groups); foreach($newgroups as $value) { if($value==$ibforums->member['mgroup']) $allowed=true; } } if ($allowed==false){ //close PHP ?> <h4>STANDARD HTML GOES HERE!!</h4> <? //open PHP exit(); } //close PHP ?> for your apology.htm include <?php include("ibf.inc.php"); function protect($groups) { global $ibforums; $allowed=false; $newgroups=split(",",$groups); foreach($newgroups as $value) { if($value==$ibforums->member['mgroup']) $allowed=true; } } if ($allowed==false){ include("path/to/apology.htm"); exit(); } ?> ensure the path is right to the file. |
![]() |
| Viewing: Dev Shed Forums > Web Design > CSS Help > Calling some html/css text within PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|