•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 430,121 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,328 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 401 | Replies: 2 | Solved
![]() |
•
•
Join Date: Apr 2008
Posts: 48
Reputation:
Rep Power: 1
Solved Threads: 3
Hey folks,
I have made an image-based shoutbox and now users can view older and newer message on the shoutbox depending on the $_GET['page'] - pagination - that works. However, since it's image based and can be linked in forums etc. on the Internet I only want it to save the gif image if $page == 1, so the newest shouts are saved onto the image. Yet the users can still view the other messages on site without it changing the saved gif image.
What I've tried so far is this:
Which, to me means that when $page == 1 then it loads the image in the browser and also saves user/helraizer.gif and if $page != 1 then it only loads it to the browser and doesn't save the gif. But even if $page == 3 then it saves that as the image and therefore the image hosted on a forum will keep changing as each user views a different thing.
I know that $page works because it changes the contents of the image, but it doesn't work within the if statement.
Can you see what's/if anything's wrong with the code? Would a switch statement be a better solution?
Thanks,
Sam
I have made an image-based shoutbox and now users can view older and newer message on the shoutbox depending on the $_GET['page'] - pagination - that works. However, since it's image based and can be linked in forums etc. on the Internet I only want it to save the gif image if $page == 1, so the newest shouts are saved onto the image. Yet the users can still view the other messages on site without it changing the saved gif image.
What I've tried so far is this:
php Syntax (Toggle Plain Text)
<?php if (isset($_GET['page']) && is_numeric($_GET['page'])) { $page = mysql_real_escape_string(htmlspecialchars($_GET['page'])); } else { $page = 1; } //other code - not relevant for this purpose if ($page == 1) { imagegif($image); // paint the image in browser imagegif($image, "user/" . $user . ".gif"); //export as gif file } elseif(!isset($filter) && $page == 1) { imagegif($image); // paint the image in browser imagegif($image, "user/" . $user . ".gif"); //export as gif file } elseif($page != 1) { imagegif($image); // paint the image in browser } elseif(isset($filter)) { imagegif($image); // paint the image in browser } else { } ?>
Which, to me means that when $page == 1 then it loads the image in the browser and also saves user/helraizer.gif and if $page != 1 then it only loads it to the browser and doesn't save the gif. But even if $page == 3 then it saves that as the image and therefore the image hosted on a forum will keep changing as each user views a different thing.
I know that $page works because it changes the contents of the image, but it doesn't work within the if statement.
Can you see what's/if anything's wrong with the code? Would a switch statement be a better solution?
Thanks,
Sam
•
•
Join Date: Mar 2008
Location: Praha, Czech Republic, Europe
Posts: 99
Reputation:
Rep Power: 1
Solved Threads: 14
Hi there,
the bug is in this if statement. Try using parentheses to make your intentions more clear:
Frankly I would just write this instead of the whole if/else if bunch:
Also, you could make the initial testing a bit more simple:
I guess you start paging with 1, which is a bit impractical.
If you start with zero you could do with a plain
the bug is in this if statement. Try using parentheses to make your intentions more clear:
php Syntax (Toggle Plain Text)
if ( (!isset($filter)) && ($page == 1) )
Frankly I would just write this instead of the whole if/else if bunch:
php Syntax (Toggle Plain Text)
if ($page == 1) imagegif($image, "user/" . $user . ".gif"); imagegif($image);
Also, you could make the initial testing a bit more simple:
php Syntax (Toggle Plain Text)
$page = max(intval($_GET['page']), 1);
If you start with zero you could do with a plain
intval($_GET['page']); Last edited by petr.pavel : Jun 10th, 2008 at 6:13 am.
Petr 'PePa' Pavel
The more information you give the more relevant answer you get.
Please consider using "Add to ... Reputation" and mark your thread as Solved if you found what you were looking for. By giving feedback you help others.
The more information you give the more relevant answer you get.
Please consider using "Add to ... Reputation" and mark your thread as Solved if you found what you were looking for. By giving feedback you help others.
•
•
Join Date: Apr 2008
Posts: 48
Reputation:
Rep Power: 1
Solved Threads: 3
Hey, thanks for the input.
I found a solution a while ago.
$page is always set, even if filter is on. Since it's for use as a signature, with the code above, if someone uses the filter then it'll change the image in the signature, which isn't good. Therefore if filter is set (regardless of whether page is set) then the image isn't saved; if filter isn't saved but page is, then it is saved and if $page != 1 then it isn't saved either.
I found a solution a while ago.
PHP Syntax (Toggle Plain Text)
if (isset($filter)) { imagepng($image); } elseif ($page == 1) { imagepng($image); imagepng($image, "./user/".$user.".png"); } else { imagepng($image); }
•
•
•
•
if ($page == 1)
imagegif($image, "user/" . $user . ".gif");
imagegif($image);
$page is always set, even if filter is on. Since it's for use as a signature, with the code above, if someone uses the filter then it'll change the image in the signature, which isn't good. Therefore if filter is set (regardless of whether page is set) then the image isn't saved; if filter isn't saved but page is, then it is saved and if $page != 1 then it isn't saved either.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: Could a switch statement be used here?
- Next Thread: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource


Linear Mode