Make your own PHP adoptables system

Need help with the site/forum/pets? Ask questions and get help from other members here.

Re: Make your own PHP adoptables system

Postby MyGodLives » Sun Dec 20, 2009 9:29 am

Thanks Nick! I'm currently working on getting my pets up to snuff, but this helped a lot!

This is my new adoptable site. It's just using the main switch-your-animals-out approach, but heck, it works.
I am an unashamed KPOP Fan!
Image
User avatar
MyGodLives
 
Posts: 258
Joined: Mon Jul 13, 2009 1:32 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby moohug4 » Sat Jan 09, 2010 2:48 pm

Hullo! Im new to this site!
i Need some help.
The 000 webhost is not working for me. can anybody recommend some others?

EDIT:
Heres my Code:
Code: Select all
<?php

//Tell the browser that we are sending it a PNG image to display
//header("Content-Type: image/png");

//Echo the contents of the image file called "Alex.png" to send it to the browser
//readfile("Alex.png");

?>


Im not sure whats wrong! Cause wHen i open firefox,(im using notepad++, and im trying to click on run, and then firefox)
nothing is showing up!!!!
Help!
moohug4
 
Posts: 1
Joined: Sat Jan 09, 2010 2:44 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Sat Jan 09, 2010 4:35 pm

That code does nothing, everything has been commented out by putting "//" at the start of the line. Please check the code from the tutorial pages again.
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Taija » Wed Jan 13, 2010 2:20 am

I have a problem with the codes in the tutorial.
The first code works, but when I extended the code to the baby rats, I get an error message that the code is flawed, and this error message I get when all of the following codes.
meine Lieblinge ^^
ImageImageImage
ja ich weiss mein englisch ist grottig ^^"
User avatar
Taija
 
Posts: 4
Joined: Sun Nov 30, 2008 8:26 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Wed Jan 13, 2010 4:00 am

Paste the error message, and the line it refers to, here.
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Turquoise » Sun Jan 17, 2010 10:55 am

Taija wrote:I have a problem with the codes in the tutorial.
The first code works, but when I extended the code to the baby rats, I get an error message that the code is flawed, and this error message I get when all of the following codes.


I was just about to say that SAME thing, how ironic... I use 000webhost, and this is the message I get:


Code: Select all
<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Code -->


You see, When I used this code:
Code: Select all
<?php

//Tell the browser that we are sending it a PNG image to display
header("Content-Type: image/png");

//Echo the contents of the image file called "dogbaby.png" to send it to the browser
readfile("dogbaby.png");

?>


dogbaby.png showed up JUST fine. I wasn't having any problems.

But once I uploaded new new simple.php and ratbaby, I got that error message (showed above).

Here is the code where the error message first started showing up:

Code: Select all
<?php

//Tell the browser that we are sending it a PNG image to display
header("Content-Type: image/png");

if ($_REQUEST['id']==1) {
    //Echo the contents of the image file called "dogbaby.png" to send it to the browser
    readfile("dogbaby.png");
} else if ($_REQUEST['id']==2) {
    //Echo the contents of the image file called "ratbaby.png" to send it to the browser
    readfile("ratbaby.png");
}

?>


And so that code, and any code I tried after it made that error message to show up.

I'm not sure what's going on here. =P
Image
User avatar
Turquoise
 
Posts: 2131
Joined: Sun Sep 21, 2008 9:12 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Turquoise » Sun Jan 17, 2010 10:59 am

Turquoise wrote:
Taija wrote:I have a problem with the codes in the tutorial.
The first code works, but when I extended the code to the baby rats, I get an error message that the code is flawed, and this error message I get when all of the following codes.


I was just about to say that SAME thing, how ironic... I use 000webhost, and this is the message I get:


Code: Select all
<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Code -->


You see, When I used this code:
Code: Select all
<?php

//Tell the browser that we are sending it a PNG image to display
header("Content-Type: image/png");

//Echo the contents of the image file called "dogbaby.png" to send it to the browser
readfile("dogbaby.png");

?>


dogbaby.png showed up JUST fine. I wasn't having any problems.

But once I uploaded new new simple.php and ratbaby, I got that error message (showed above).

Here is the code where the error message first started showing up:

Code: Select all
<?php

//Tell the browser that we are sending it a PNG image to display
header("Content-Type: image/png");

if ($_REQUEST['id']==1) {
    //Echo the contents of the image file called "dogbaby.png" to send it to the browser
    readfile("dogbaby.png");
} else if ($_REQUEST['id']==2) {
    //Echo the contents of the image file called "ratbaby.png" to send it to the browser
    readfile("ratbaby.png");
}

?>


And so that code, and any code I tried after it made that error message to show up.

I'm not sure what's going on here. =P


P.S. - My site is here... not sure if you need it for reference or anything?
Image
User avatar
Turquoise
 
Posts: 2131
Joined: Sun Sep 21, 2008 9:12 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Sun Jan 17, 2010 2:06 pm

Turquoise wrote:And so that code, and any code I tried after it made that error message to show up.

I'm not sure what's going on here. =P

You're not using the right URL to view the image. As the text says, you need to view simple.php?id=1 or simple.php?id=2, not just simple.php.
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Turquoise » Sun Jan 17, 2010 7:11 pm

Nick wrote:
Turquoise wrote:And so that code, and any code I tried after it made that error message to show up.

I'm not sure what's going on here. =P

You're not using the right URL to view the image. As the text says, you need to view simple.php?id=1 or simple.php?id=2, not just simple.php.


Oh okay, thanks.

I tried that and it's fine now.
Image
User avatar
Turquoise
 
Posts: 2131
Joined: Sun Sep 21, 2008 9:12 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Turquoise » Mon Jan 18, 2010 3:56 am

Me Again! =3

Okay, so I am setting up the adoptables system, and I have a problem when you adopt.

I got the mainpage.php up, but the problem is that when you adopt a "dog" or "rat", it takes you to the adopt.php page, but instead of showing the picture of the adoptable you adopted, it shows a box with a red "x".

The page is located HERE.

Here is my coding for the pages:

adopt.php
Code: Select all
<html>
<head>
</head>

<body>
<?php

require("adopttools.php");

/* Our visitor has picked an adoptable they want, its id is in $_REQUEST['id']. Find that
 * adoptable in adoptables.xml
 */
$adoptable=find_adoptable($_REQUEST['id']);

/* To randomly pick a variation from that adoptable, we're going have to do a little maths with
 * random numbers.
 *
 * First we find the sum of all the 'chance' attributes for this adoptable...
 */

$sum=0;
foreach ($adoptable->variation as $variation) {
    $sum=$sum + $variation['chance'];
}

/* Now we can generate a random number which goes from 0.0 to that sum. This will help us
 * pick a variation.
 */
$random=lcg_value()*$sum;

$sum=0;
foreach ($adoptable->variation as $variation) {
    $sum = $sum + $variation['chance'];
     
    if ($random <= $sum) {
        //Choose this variation
        $v_id=$variation['id'];
        break;
    }
}

?>

<p><img src="simple.php?a=<?php echo $_REQUEST['id'];?>&amp;v=<?php echo $v_id;?>"></p>
<p>Thanks for adopting this pet! :). Here is the adoption code for your pet:</p>
<p><textarea cols="60" rows="2"><img src="http://www.mywebsite.com/simple.php?a=<?php echo $_REQUEST['id'];?>&amp;v=<?php echo $v_id;?>"></textarea></p>
</body>
</html>


adopttools.php
Code: Select all
<?php

//Load the adoptables XML file
$adoptxml=simplexml_load_file("adoptables.xml");

//Find the adoptable from adoptables.xml which has the right id
function find_adoptable($id) {
    global $adoptxml;

    //For each 'adoptable' tag which is available
    foreach ($adoptxml->adoptable as $adoptable) {
     
        //Is this adoptable's id the same as the one that the user wants to see?
        if ($adoptable['id']==$id) {
            //Yes, it is
            return $adoptable;
        }
    }
     
    return NULL; //We couldn't find an adoptable with that ID
}

//Find the variation with the given adoptable id and variation id
function find_variation($adoptid, $varid) {

    $adoptable=find_adoptable($adoptid);

    //For each 'variation' tag which is available
    foreach ($adoptable->variation as $variation) {
     
        //Is this variation's id the same as the one that the user wants to see?
        if ($variation['id']==$varid) {
            //Yes, it is
            return $variation;
        }
    }
     
    return NULL; //We couldn't find the variation with that ID
}

?>


adoptables.php
Code: Select all
<adoptables>

<adoptable id="1">
    <variation id="1" chance="1.0">
        <age image="dogbaby.png" />
        <age date="2010-1-15" image="dogpuppyrare.png" />
        <age date="2010-1-16" image="dogadultrare.png" />
    </variation>
    <variation id="2" chance="5.0">
        <age image="dogbaby.png" />
        <age date="2010-1-14" image="dogpuppy.png" />
        <age date="2010-1-16" image="dogadult.png" />
    </variation>
</adoptable>

<adoptable id="2">
    <variation id="1" chance="1.0">
        <age image="ratbaby.png" />
        <age date="2010-1-15" image="ratadult.png" />
    </variation>
</adoptable>

</adoptables>


Thanks!


EDIT: Now for some reason I am getting a lot of error messages, here: CLICK, and Here: CLICK. mainpage.php is working fine, but those error messages show once you have "adopted" the pet. :)

Sorry for taking so much of your time with this!
Last edited by Turquoise on Tue Jan 19, 2010 12:48 am, edited 1 time in total.
Image
User avatar
Turquoise
 
Posts: 2131
Joined: Sun Sep 21, 2008 9:12 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Who is online

Users browsing this forum: No registered users and 2 guests