#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep 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>
  2. #2
  3. Freelance PHP/MySQL Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Bham, UK
    Posts
    339
    Rep Power
    12
    you can embed your php in your html like this

    <?
    if(condition is true){
    ?>

    html goes here

    <?
    }
    else {
    ?>

    html goes here

    <?
    }
    ?>
  4. #3
  5. No Profile Picture
    Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    Boston Ma.
    Posts
    1,529
    Rep Power
    0
    Hi

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

    F!
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep 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();
  8. #5
  9. Freelance PHP/MySQL Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Bham, UK
    Posts
    339
    Rep Power
    12
    <?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
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep 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();

    }

    }

    ?>
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep 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...
  14. #8
  15. Freelance PHP/MySQL Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Bham, UK
    Posts
    339
    Rep Power
    12
    email your full code
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    Hi pprince -
    Did you get the email?
  18. #10
  19. Freelance PHP/MySQL Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Bham, UK
    Posts
    339
    Rep Power
    12
    nah, where did u send it?
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    I just used this Devshed system.
  22. #12
  23. Freelance PHP/MySQL Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Bham, UK
    Posts
    339
    Rep Power
    12
  24. #13
  25. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    Hi Paul -
    Many thanks for your email and the fixed code - you're a splendid chap!
    Regards, Steve.
  26. #14
  27. Freelance PHP/MySQL Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Bham, UK
    Posts
    339
    Rep Power
    12
    Steve,

    post the answer for others to use

    Paul
    -Paul Prince
    -www.tmwc.co.uk
  28. #15
  29. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep 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.

IMN logo majestic logo threadwatch logo seochat tools logo