Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php noob trying to learn.

    I'm trying to get my hands wet with some simple php, as I've never used it before.

    I know that I can read the contents of a file and print it out on screen by
    $y=file_get_contents($a);
    echo $y;

    where $a is the name of the file.

    What I want to do is have the users click different buttons, each of which would send them to a link such as /index.php?a=filename.txt or /index.php?a=filename2.txt or /index.php?a=filename3.txt

    I can't figure out how to get my code to READ what that filename is.

    I thought I could just send it to the url as /index.php?a=filename.txt and then do

    $y=file_get_contents($a);
    echo $y;

    but it returns nothing.

    Help please.

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,846
    Thanks
    21
    Thanked 157 Times in 148 Posts
    PHP Code:
    $y=file_get_contents($_GET['a']);
    echo 
    $y
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    awesome. thanks..

    now what could i do to make the following happen?

    Send a variable "a" , append a .txt to it, and then call it with the

    $y=file_get_contents($_GET['a']);
    echo $y;

  • #4
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,100
    Thanks
    2
    Thanked 23 Times in 23 Posts
    PHP Code:
    $y=file_get_contents($_GET['a'].".txt");
    echo 
    $y
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #5
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,846
    Thanks
    21
    Thanked 157 Times in 148 Posts
    PHP Code:
    $file $_GET['a'] . ".txt";
    $y=file_get_contents($file );
    echo 
    $y
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #6
    New Coder
    Join Date
    Feb 2006
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Keyser520
    awesome. thanks..

    now what could i do to make the following happen?

    Send a variable "a" , append a .txt to it, and then call it with the

    $y=file_get_contents($_GET['a']);
    echo $y;
    answered my own question

    <html>
    <body>

    <?php

    $b=($_GET['a']).".txt";
    echo $b;
    $y=file_get_contents($_GET['a'].".txt");
    echo $y;



    ?>

    </html>
    </body>



    Now, will there be any problem with this method if more than one person is using the page at the same time? Will the variables get confused based on the last person to visit a site or is localally stored?

  • #7
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,846
    Thanks
    21
    Thanked 157 Times in 148 Posts
    how many people open and read a file is only limited by the bandwidth on your server
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #8
    New Coder
    Join Date
    Feb 2006
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by chump2877
    how many people open and read a file is only limited by the bandwidth on your server

    ok, but i was asking if the variable being passed to it -- the "a" would change everytime someone clicked a different link.


    Is there a way that I can assign the variable a certain string of text IF there is no variable passed in?

    i.e if I am using the code

    <?php
    $b=($_GET['a']).".txt";
    echo $b;
    $y=file_get_contents($_GET['a'].".txt");
    echo $y;
    ?>

    then it will work find if the link is /index.php?a=welcome but I want it to display another message if the link is just /index.php

  • #9
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,846
    Thanks
    21
    Thanked 157 Times in 148 Posts
    but i was asking if the variable being passed to it -- the "a" would change everytime someone clicked a different link.
    yes, if a=file1 (in your URL), then $_GET['a'] will contain "file1"....$_GET['a'] equals whatever value "a" that was passed to it....so i thnk what you are asking is you can have multiple buttons pass "a" via the GET method, and you only need to declare $_GET['a'] once on the subsequent page...because you can only clikc on one button at a time...$_GET['a'] will reset itself the next time around when another button is clicked in which "a" has a different value...

    PHP Code:
    if (empty($_GET['a']))
    {
    $file "yourstring.txt"
    }
    else
    {
    $file $_GET['a'] . ".txt";
    }
    $y=file_get_contents($file );
    echo 
    $y
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #10
    New Coder
    Join Date
    Feb 2006
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by chump2877
    yes, if a=file1 (in your URL), then $_GET['a'] will contain "file1"....$_GET['a'] equals whatever value "a" that was passed to it....so i thnk what you are asking is you can have multiple buttons pass "a" via the GET method, and you only need to declare $_GET['a'] once on the subsequent page...because you can only clikc on one button at a time...$_GET['a'] will reset itself the next time around when another button is clicked in which "a" has a different value...

    PHP Code:
    if (empty($_GET['a']))
    {
    $file "yourstring.txt"
    }
    else
    {
    $file $_GET['a'] . ".txt";
    }
    $y=file_get_contents($file );
    echo 
    $y

    Ok, that code makes sense.. You've been a big help, and I will stop pestering you soon, I promise.

    Do you have a book or course that you would recommend for someone wanting to become proficient in php?

    The question that I was asking is this.

    Imagine 3 users-- user 1 clicks on the link that brings them to /index.php?a=welcome and then user 2 clicks on the link for /index.php?a=aboutus .
    When user 3 clicks on the link for /index.php will "a" have the value of "welcome" or of "aboutus" or of nul?

    I need it to have a value of "nul"

  • #11
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,846
    Thanks
    21
    Thanked 157 Times in 148 Posts
    lol, why are there 3 users? You can only control the experience of one user at a time....And how many different buttons/links are there?

    Foremost, what is the larger picture here? What are you ultimately trying to do with this code?

    As far as PHP references/books/tutorials, www.php.net is an excellent resource....but to actually learn PHP, I would get a book out of the library, or buy one from a bookstore (library is cheaper).....there are hundreds of books on PHP for beginners, with step-by-step tutorials thru the learning process...Sorry i cant think of any on hand, try Amazon.com
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #12
    New Coder
    Join Date
    Feb 2006
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by chump2877
    lol, why are there 3 users? You can only control the experience of one user at a time....And how many different buttons/links are there?

    Foremost, what is the larger picture here? What are you ultimately trying to do with this code?

    As far as PHP references/books/tutorials, www.php.net is an excellent resource....but to actually learn PHP, I would get a book out of the library, or buy one from a bookstore (library is cheaper).....there are hundreds of books on PHP for beginners, with step-by-step tutorials thru the learning process...Sorry i cant think of any on hand, try Amazon.com
    Ok, here is the "larger picture".

    http://www.runeescape.net


    Any ideas for better coding? :-)

    Thanks for all your help, btw.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •