CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 12th, 2003, 09:30 AM
steve_e steve_e is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 steve_e User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #2  
Old September 12th, 2003, 09:44 AM
pprince's Avatar
pprince pprince is offline
Freelance PHP/MySQL Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Bham, UK
Posts: 340 pprince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 34 m 21 sec
Reputation Power: 5
you can embed your php in your html like this

<?
if(condition is true){
?>

html goes here

<?
}
else {
?>

html goes here

<?
}
?>

Reply With Quote
  #3  
Old September 12th, 2003, 09:47 AM
Fataqui Fataqui is offline
Senior Member
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Location: Boston Ma.
Posts: 1,530 Fataqui User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 42 sec
Reputation Power: 0
Hi

You can do what pprince said or you could use switch(); !

F!

Reply With Quote
  #4  
Old September 12th, 2003, 09:57 AM
steve_e steve_e is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 steve_e User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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();

Reply With Quote
  #5  
Old September 12th, 2003, 09:59 AM
pprince's Avatar
pprince pprince is offline
Freelance PHP/MySQL Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Bham, UK
Posts: 340 pprince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 34 m 21 sec
Reputation Power: 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();

?>
__________________
-Paul Prince
-www.tmwc.co.uk

Reply With Quote
  #6  
Old September 13th, 2003, 01:45 AM
steve_e steve_e is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 steve_e User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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();

}

}

?>

Reply With Quote
  #7  
Old September 13th, 2003, 02:40 AM
steve_e steve_e is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 steve_e User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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...

Reply With Quote
  #8  
Old September 15th, 2003, 03:04 AM
pprince's Avatar
pprince pprince is offline
Freelance PHP/MySQL Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Bham, UK
Posts: 340 pprince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 34 m 21 sec
Reputation Power: 5
email your full code

Reply With Quote
  #9  
Old September 16th, 2003, 03:34 AM
steve_e steve_e is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 steve_e User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi pprince -
Did you get the email?

Reply With Quote
  #10  
Old September 16th, 2003, 03:36 AM
pprince's Avatar
pprince pprince is offline
Freelance PHP/MySQL Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Bham, UK
Posts: 340 pprince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 34 m 21 sec
Reputation Power: 5
nah, where did u send it?

Reply With Quote
  #11  
Old September 16th, 2003, 03:43 AM
steve_e steve_e is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 steve_e User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I just used this Devshed system.

Reply With Quote
  #12  
Old September 16th, 2003, 03:44 AM
pprince's Avatar
pprince pprince is offline
Freelance PHP/MySQL Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Bham, UK
Posts: 340 pprince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 34 m 21 sec
Reputation Power: 5

Reply With Quote
  #13  
Old September 16th, 2003, 05:57 AM
steve_e steve_e is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 steve_e User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Paul -
Many thanks for your email and the fixed code - you're a splendid chap!
Regards, Steve.

Reply With Quote
  #14  
Old September 16th, 2003, 05:59 AM
pprince's Avatar
pprince pprince is offline
Freelance PHP/MySQL Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Bham, UK
Posts: 340 pprince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 34 m 21 sec
Reputation Power: 5
Steve,

post the answer for others to use

Paul

Reply With Quote
  #15  
Old September 16th, 2003, 06:14 AM
steve_e steve_e is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 steve_e User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > Calling some html/css text within PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump