Jump to content

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


Brian77

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.
Link to comment
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.

Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.