Using Include for PHP

[code]
<?php
include ('./php/config.php');

&connect = mysql_connect($host,$user,$pw);
echo mysql_error();
mysql_select_db($db);
echo mysql_error();

$table1 = 'CharInfo';
$table2 = 'Atts';
$table3 = 'Talents';
$table4 = 'Skills';
$table5 = 'Knowledges';
$table6 = 'Advantages';
?>
[/code]

This is the PHP page trying to include another 'template' php page holding variables for servern, username, pw and database.

[code]
<$php
$host = 'mysql';
$user = 'SomeUser';
$pw = 'SomePW';
$db = 'CharSheets';
?>
[/code]

I guess what I am asking is, is my include call out correct, and how must I set my php file that is being included? Every time I run the html and php code I get a white blank page. But yet if I take off the include and place the variables on the main page itself, it works fine. Someone please save me. Thank you very much.

the darthmoob

Comments

  • : [code]
    : <$php [red]Should this not be <?php instead?[/red]
    : $host = 'mysql';
    : $user = 'SomeUser';
    : $pw = 'SomePW';
    : $db = 'CharSheets';
    : ?>
    : [/code]

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : : [code]
    : : <$php [red]Should this not be <?php instead?[/red]
    : : $host = 'mysql';
    : : $user = 'SomeUser';
    : : $pw = 'SomePW';
    : : $db = 'CharSheets';
    : : ?>
    : : [/code]
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :
    Yes I'm sorry, I typed it in wrong, on the php coding I have the <?php start, I had to double check when you asked though. Lol. Thanks anyways Johnathan, I can't figure it out, it just loads a blank page.

    the darthmoob

  • hey Jonathan, put this at the top of template.php

    error_reporting(E_ALL);

    Your server might have reporting off (mine did)

    Some other tips..

    echo "blah1";
    echo "blah2";

    put the first echo statement in template.php and the second one in config.php

    Save and view.. if you don't get an error and blah2 doesn't show up then somethings wrong =P

    If the include is not includeing the file, it's likely that it is not pointing at the right file.

    BTW why do you need the period (.) before the file address? did you mean to put two periods? (..) to go up one directory.. I don't know very much about the single period but i believe it is only used to point to the current directory and isn't needed for anything else. But i might be wrong.

    [b][blue]Snoochie Boochies[/blue][/b]

  • [code]
    <?php
    include ('/php/config.php');
    echo "blah2";
    &connect = mysql_connect($host,$user,$pw);
    echo mysql_error();
    mysql_select_db($db);
    echo mysql_error();

    $table1 = 'CharInfo';
    $table2 = 'Atts';
    $table3 = 'Talents';
    $table4 = 'Skills';
    $table5 = 'Knowledges';
    $table6 = 'Advantages';

    $insert_data_Info = "INSERT INTO
    $table1 (CharName, PlayerName, Password, Email,
    Webpage, Age, Sex, Nature, Demeanor, Venue, Type,
    Concept, Description, ExitMessage, Icon)
    VALUES ('$CharName', '$PlayerName',
    '$Password','$Email','$URL','$Age','$Sex','$Nature',
    '$Demeanor','$Venue','$Type','$Concept','$Description',
    '$ExitMessage','$Icon')";
    ?>
    [/code]

    Template - (/php/config.php)<-location of included file in file manager.
    [code]
    <?php
    error_reporting(E_ALL);
    echo "Blah1";
    $host = 'somehost';
    $user = 'someuser';
    $pw = 'somepw';
    $db = 'CharSheets';
    ?>
    [/code]

    Ok Skylar, I went ahead and corrected what you wanted, but I still get a blank white page. Is there anything special I need to do to the template file that is included? Does my coding look ok to you, or is there something I wish to change. I wanted to use the include property for security purposes, so that people cannot right click and view source to see the user names and passwords. Thanks for your help.

    the darthmoob
  • [b][red]This message was edited by skylar at 2004-3-23 13:43:32[/red][/b][hr]

    i get an error on line 4 =)


    an amperstand (&) instead of dollar sign ($)

    check that and tell me if you still get a problem


    /sky






    --------------------------------
    You also need to run your query..

    mysql_query($insert_data_Info);



    --------------------------------
    AND..

    Security? Nobody can see your php code, unless they can see the textfile of the php that created the html (the sourcefile)
    Php spits out (pre-processed)html from the server, the client just reads the html. Right click on the page and view the source and you will find NO php code.

    Thats why php IS THE SHIT!!!
  • Hi,

    Darthmoob - sorry I didn't get back to you quicker. Bad Things happened to my foot. I can just about walk again...almost. :-)

    Include statements...they are not relative to the root of the website itself, to my understanding, but are related to the filesystem on the server you're working on. You're better off using relative paths. As for what a single . means, that means look in the current folder. .. means the folder below. So if you have a script in the root of your website and you had a folder in the root of your site as well called php and include.php was in there, you'd use the path php/include.php or if you want to be explicit (and it may be a good idea) ./php/include.php.


    : Ok Skylar, I went ahead and corrected what you wanted, but I still
    : get a blank white page. Is there anything special I need to do to
    : the template file that is included?
    1) Put an echo statement immediately before your include statement, and another immediately after. See if either appear. I don't know if they are done at compile time or runtime, maybe someone else knows or will go look at the manual.

    2) Do included files have to "return true" in PHP, like in Perl? (Note: I'm a Perl guy really...) If so, try putting 1; on a line of its own before the closing ?> in the file to be included.

    3) Check your server error logs. Contain anything?

    : Does my coding look ok to you, or is there something I wish to
    : change. I wanted to use the include property for security purposes,
    : so that people cannot right click and view source to see the user
    : names and passwords. Thanks for your help.
    :
    Uh....remember PHP code is executed *server side*, not client side, so anything between <?php and ?> is never sent to the browser, but is executed on the server. Unless you get your server configuration Really Wrong, of course. :-) All the same, connection details want to be in an include so you don't have to change them throught a gazillion files if you want to install the script on another server.

    Any luck?

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • nah, you don't need to return anything from an included file. You don't even need to name it (.php) you could call it .txt and any php in it would still be compiled and run.

    If you wish to exit out of an included file abruptly you could always do return; or return true or something, just like a function (which is a good way of explaining them)
    [b][blue]Snoochie Boochies[/blue][/b]

  • : nah, you don't need to return anything from an included file.
    OK, I've added it to my (mental) list of Perl/PHP differences. Thanks for the info. :-)

    : You don't even need to name it (.php) you could call it .txt and any
    : php in it would still be compiled and run.
    :
    Yeah, I've seen plenty of people call them .lib or have no extension.

    : If you wish to exit out of an included file abruptly you could
    : always do return; or return true or something, just like a function
    : (which is a good way of explaining them)
    :
    Hmmmm...so does that means that variables declared inside an include file are lexically scoped inside that include and are destroyed at the end of the include? If so, that could be Darthmoob's problem.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • [b][red]This message was edited by skylar at 2004-3-23 14:21:49[/red][/b][hr]

    : : nah, you don't need to return anything from an included file.
    : OK, I've added it to my (mental) list of Perl/PHP differences. Thanks for the info. :-)
    :
    : : You don't even need to name it (.php) you could call it .txt and any
    : : php in it would still be compiled and run.
    : :
    : Yeah, I've seen plenty of people call them .lib or have no extension.
    :
    : : If you wish to exit out of an included file abruptly you could
    : : always do return; or return true or something, just like a function
    : : (which is a good way of explaining them)
    : :
    : Hmmmm...so does that means that variables declared inside an include file are lexically scoped inside that include and are destroyed at the end of the include? If so, that could be Darthmoob's problem.
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :


    Nope, it is EXACTLY as if all text in an include existed on the line that the include was issued.

    [code]a.php

    <?php

    $b = '2';

    echo 1;
    include("b.php");
    echo $c;

    ?>


    ----------------------------
    b.php

    <?php
    $c = '3';
    echo $b;
    ?>


    ----------------------------
    [red]a.php prints 123[/red]

    [/code]

    AND IS EXACTLY THE SAME AS:

    [code]a.php

    <?php

    $b = '2';

    echo 1;
    $c = '3';
    echo $b;
    echo $c;

    ?>

    ----------------------------
    [red]a.php prints 123[/red]

    [/code]




    The only difference is that if included files contain errors, the file that requested the included file will not die (the included file will). The error is outputed as if the file that was included contained a echo statement that returned an error.

    (as if that makes any sence lol)

    [b][blue]Snoochie Boochies[/blue][/b]

















  • : [b][red]This message was edited by skylar at 2004-3-23 14:21:49[/red][/b][hr]
    :
    : : : nah, you don't need to return anything from an included file.
    : : OK, I've added it to my (mental) list of Perl/PHP differences. Thanks for the info. :-)
    : :
    : : : You don't even need to name it (.php) you could call it .txt and any
    : : : php in it would still be compiled and run.
    : : :
    : : Yeah, I've seen plenty of people call them .lib or have no extension.
    : :
    : : : If you wish to exit out of an included file abruptly you could
    : : : always do return; or return true or something, just like a function
    : : : (which is a good way of explaining them)
    : : :
    : : Hmmmm...so does that means that variables declared inside an include file are lexically scoped inside that include and are destroyed at the end of the include? If so, that could be Darthmoob's problem.
    : :
    : : Jonathan
    : :
    : : ###
    : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : :
    : :
    :
    :
    : Nope, it is EXACTLY as if all text in an include existed on the line that the include was issued.
    :
    : [code]a.php
    :
    : <?php
    :
    : $b = '2';
    :
    : echo 1;
    : include("b.php");
    : echo $c;
    :
    : ?>
    :
    :
    : ----------------------------
    : b.php
    :
    : <?php
    : $c = '3';
    : echo $b;
    : ?>
    :
    :
    : ----------------------------
    : [red]a.php prints 123[/red]
    :
    : [/code]
    :
    : AND IS EXACTLY THE SAME AS:
    :
    : [code]a.php
    :
    : <?php
    :
    : $b = '2';
    :
    : echo 1;
    : $c = '3';
    : echo $b;
    : echo $c;
    :
    : ?>
    :
    : ----------------------------
    : [red]a.php prints 123[/red]
    :
    : [/code]
    :
    : The only difference is that if included files contain errors, the file that requested the included file will not die (the included file will). The error is outputed as if the file that was included contained a echo statement that returned an error.
    :
    But you can still return from the middle of an include file as if it were a function? Yeah, OK, that's weird. Or do all variables get put into a global symbol table / "namespace" (you're getting namespaces in PHP5, I believe...) and you don't have lexical scoping?

    : (as if that makes any sence lol)
    :
    To me, many PHP language design decisions just don't, I'm afraid.

    Again, thanks for the clarifications.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : But you can still return from the middle of an include file as if it were a function? Yeah, OK, that's weird. Or do all variables get put into a global symbol table / "namespace" (you're getting namespaces in PHP5, I believe...) and you don't have lexical scoping?


    I believe so, includes are sepparate but equal (lol)


    : : (as if that makes any sence lol)
    : :
    : To me, many PHP language design decisions just don't, I'm afraid.


    I agree.. but php is so damn nice.. no calling in other modules (perl) no worrying about undeclared variables, easy scripting.
    A hella lot better than perl imo


    But i still miss $var = qq~string stuff~;

    That was an awesome feature.. in php it's

    $var = <<<qq
    string stuff
    qq;

    Which sux.. three lines? =




    : Again, thanks for the clarifications.


    np

    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    [b][blue]Snoochie Boochies[/blue][/b]

  • : : But you can still return from the middle of an include file as if it were a function? Yeah, OK, that's weird. Or do all variables get put into a global symbol table / "namespace" (you're getting namespaces in PHP5, I believe...) and you don't have lexical scoping?
    :
    :
    : I believe so, includes are sepparate but equal (lol)
    :
    Fair enough.

    : : : (as if that makes any sence lol)
    : : :
    : : To me, many PHP language design decisions just don't, I'm afraid.
    :
    : I agree.. but php is so damn nice..
    :
    It depends on what matters to you. I admit PHP is a nice concept, but then I think VB is a great tool too. Sadly, the language design of each of them doesn't go too well with me. Not that PHP is as bad as VB. :-)

    : no calling in other modules (perl)
    Yes, because we all love having to recompile PHP to upgrade our database connectivity drivers. Modularity is a good thing, IMHO. I'd much sooner have things like database support in a loadable module than built into the core of the language, slowing down every script that doesn't use it. I also dislike the mysql_ prefix before everything, and the lack of abstraction between databases. Thus why almost everyone makes classes, and "include"s them. So then we're as well off as if we just used Perl and written use DBI; and had a nice clean OO interface to begin with.

    : no worrying about undeclared variables, easy scripting.
    You can use undeclared variables in Perl if you want. Alternatively you just put use strict; at the top of your script and it says "no go" and you can't. It's what you make of it.

    : A hella lot better than perl imo
    :
    You're welcome to your opinion. I learnt Perl first, then looked at PHP very carefully as it seemed very popular. So far, nothing has been able to attract me, though PHP5 tempted me for a little while. Now my company has tens of thousands of lines of Perl base code (and hundreds of thousands of lines of Perl in systems we've developed and deployed) so moving mean we had to be making a BIG saving.

    : But i still miss $var = qq~string stuff~;
    :
    : That was an awesome feature.. in php it's
    :
    : $var = <<<qq
    : string stuff
    : qq;
    :
    : Which sux.. three lines? =
    :
    The second is more of a rip of Perl's heredocs...apart from they were << and you could use any name you wanted, not just qq. But maybe you can in PHP too?

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : : : But you can still return from the middle of an include file as if it were a function? Yeah, OK, that's weird. Or do all variables get put into a global symbol table / "namespace" (you're getting namespaces in PHP5, I believe...) and you don't have lexical scoping?
    : :
    : :
    : : I believe so, includes are sepparate but equal (lol)
    : :
    : Fair enough.
    :
    : : : : (as if that makes any sence lol)
    : : : :
    : : : To me, many PHP language design decisions just don't, I'm afraid.
    : :
    : : I agree.. but php is so damn nice..
    : :
    : It depends on what matters to you. I admit PHP is a nice concept, but then I think VB is a great tool too. Sadly, the language design of each of them doesn't go too well with me. Not that PHP is as bad as VB. :-)
    :
    : : no calling in other modules (perl)
    : Yes, because we all love having to recompile PHP to upgrade our database connectivity drivers. Modularity is a good thing, IMHO. I'd much sooner have things like database support in a loadable module than built into the core of the language, slowing down every script that doesn't use it. I also dislike the mysql_ prefix before everything, and the lack of abstraction between databases. Thus why almost everyone makes classes, and "include"s them. So then we're as well off as if we just used Perl and written use DBI; and had a nice clean OO interface to begin with.


    I guess i haven't had any problems being that i only use MySQL and normal web programming


    : : no worrying about undeclared variables, easy scripting.
    : You can use undeclared variables in Perl if you want. Alternatively you just put use strict; at the top of your script and it says "no go" and you can't. It's what you make of it.


    I meant as opposed to Java or visual basics
    Perl is really nice too


    : : A hella lot better than perl imo
    : :
    : You're welcome to your opinion. I learnt Perl first, then looked at PHP very carefully as it seemed very popular. So far, nothing has been able to attract me, though PHP5 tempted me for a little while. Now my company has tens of thousands of lines of Perl base code (and hundreds of thousands of lines of Perl in systems we've developed and deployed) so moving mean we had to be making a BIG saving.


    I learned perl first too (after html and javascript LOL)
    The site i was working with switched over to phpNuke so i had to change all my files over from .cgi to .php = (that was fun)
    Ever since i have loved it.

    $bah ~= (?)/pregreplacestring/replacetext/i;

    was nice but all of the weird constructs makes the language hard to debug.

    And perl.com is nowhere near as userfriendly as php.net
    Making php extremely (!!!) easy to understand in a short period of time.
    ---
    I was told by some developers for the game (imperialconflict.com) that cgi does a lot more calls for something or does something extra that php doesn't do.. I don't remember.. i'm not too good with the terminology.




    : : But i still miss $var = qq~string stuff~;
    : :
    : : That was an awesome feature.. in php it's
    : :
    : : $var = <<<qq
    : : string stuff
    : : qq;
    : :
    : : Which sux.. three lines? =
    : :
    : The second is more of a rip of Perl's heredocs...apart from they were << and you could use any name you wanted, not just qq. But maybe you can in PHP too?

    yep.. i use this:
    echo <<<eof
    blah
    eof;

    It can get buggy tho.. if there is a space before or after 'eof;' then the script crashes.. (you can't format it along with the rest of the script which sux)


    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :


    [b][blue]Snoochie Boochies[/blue][/b]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories