Jump to content

Archived

This topic is now archived and is closed to further replies.

Brian77

PHP game...refresh page it's on after Submit

Recommended Posts

I really don't know where to ask this question, I even tried over at where they make this game and they never answered...so here it goes.

I play an RPG game on my fourm. There is 4 directions one may travel on the main zone.php page. Upon clicking where they want to go, they are taken to a page that tells them that it was successful and click here to return to the previous page. I would like them to only click ONCE the direction they want to go, and basically refreshing the zone.php file, and being in the new area they chose. How can I accomplish this? It would save clicking, and it would also save me bandwidth because that whole page isn't coming up anymore. This is at the end of one direction that is in my zone.php page.

//Update character zone
$sql = " UPDATE  " . RPG_CHARACTERS_TABLE . "
SET character_area = '$destination_id'
WHERE character_id = '$user_id' ";
if( !($result = $db->sql_query($sql)) )
message_die(GENERAL_ERROR, 'Could not update character zone', '', __LINE__, __FILE__, $sql);

rpg_previous( Rpg_zone_change_success , rpg_zones , '' );
break;

I have already tried removing the rpg_previous( Rpg_zone_change_success , rpg_zones , '' ); line of text from all points, and it worked, but it didn't refresh the page. Ex: I was in Area 1, clicked North to Area 2, and it brought back my zone.php page....but I was STILL in Area 1, but according to my DB, I really was in Area 2, and hitting F5 would change it.

Share this post


Link to post
Share on other sites
So when a user click on a link, it sends them to a new location.  So is the page refreshed with the locations new attributes? Or are they being forwared to a new page each time and you want to just make it reload the current page with the new location within it?

You can redirect them to the same page with header()

so

[code]
<?php


$movetoID = 453;  // SQL id for the location they wish to move to

header("Location: {$_SERVER['PHP_SELF']}/location.php?locid={$movetoID}");

exit();
?>
[/code]
Though you can see people could just input their own room locations into the URL which is umm a bit of a cheat.  I guess you would do some sort of POST, which would at least stop them from entering where ever they want to go.

Share this post


Link to post
Share on other sites
Do a header relocation:

[code=php:0]
//Update character zone
$sql = "UPDATE  " . RPG_CHARACTERS_TABLE . "
          SET character_area = '$destination_id'
          WHERE character_id = '$user_id' ";

if( !($result = $db->sql_query($sql)) ){
   // Zoning failed
   $zoned = false;
} else {
   $zoned = true;
}

// go back to zone page
Header("Location: zone.php?zoned=".$zoned);

// Stop further page execution
exit;
[/code]

and on your zone.php, where you show the current zone info:

[code=php:0]
if($_GET['zoned'] == true){
   // Zone was successful
} else {
   // Zoning failed
}
[/code]

Share this post


Link to post
Share on other sites
Adding that to the zone.php file works, slightly, but it doesn't actually refresh the page to the new area without pressing F5 or refresh.

Share this post


Link to post
Share on other sites
That sounds like a caching problem. Try this:

[code=php:0]
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
[/code]

More information on cache control can be found here:

http://us2.php.net/manual/en/function.header.php

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.