redirect

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

redirect

Post by pretender5552 »

I am trying to set it up so that a table appears after you do a job, the job is done by being sent to a separate php redirecting immediantly you back when the experience and money is add, so I am wondering how to create an if statement that is triggered by a redirect.
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: redirect

Post by PaxBritannia »

The easy way to do this would be to pass a get variable

Code: Select all

index.php?from=page1
in the redirect url, and test for it in the receiving page.

pax.
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: redirect

Post by pretender5552 »

alright I get the get command so how would you write it?
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: redirect

Post by PaxBritannia »

You get the get, good! :D

Just request the variable and if it is true, then run the script:

url with get variable:

Code: Select all

index.php?redirect=1
detect get variable:

Code: Select all

$redirect = $_REQUEST['redirect'];

if($redirect==1){
	//it was redirected
}else{
	// it was not redirected
}
Remember, this script is not foolproof, that is, someone could just type it into their browser, and the script would think it was form a redirect. There are other ways to confirm it, but they are a tad advanced.

pax.
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: redirect

Post by pretender5552 »

I got the variables in place so that if they are not of a high enough level or if they don't have enough energy they just get redirected back without the added stats.

edit I don't quite get how you have the url and get variable
edit ah I got it had to go back to the redirect go and insert an ?job1=1
edit I don't think it will work because I can't put a include_once command.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: redirect

Post by Chris »

Why not? Are you trying to include something twice?
Fighting for peace is declaring war on war. If you want peace be peaceful.
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: redirect

Post by pretender5552 »

No the page I would have to include_once is the one that adds experience and money then redirects if I include that it will keep repeatedly adding experience and money then redirecting until I am out of energy.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: redirect

Post by Chris »

Where there's a will there's a way. Can I see your code. Maybe I could point you in the right direction.
Fighting for peace is declaring war on war. If you want peace be peaceful.
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: redirect

Post by pretender5552 »

This is the page that it gets redirected to

Code: Select all

<?php
include_once 'connect.php';
include_once 'bannerbox.php';
?>

<link href="style.css" rel="stylesheet" type="text/css" />

<?php

$playerinfo="SELECT * from player where name='Bryan'";
$playerinfo2=mysql_query($playerinfo) or die((mysql_error()));
$playerinfo3=mysql_fetch_array($playerinfo2);

$jobsinfo = "SELECT * from jobs where name = 'jobs1'";
$jobsinfo2 = mysql_query($jobsinfo) or die (mysql_error());
$jobsinfo3 = mysql_fetch_array($jobsinfo2);

$experienceneeded = ($playerinfo3['level'] * 10) * 1.2;

if ($playerinfo3['experience'] >= $experienceneeded){
	echo "<meta http-equiv='refresh' content='0;url=http://www.immortal.x10.mx/leveljobs.php'>";
}
$redirect = $_REQUEST['job1'];

if($redirect==1){
echo "<br><br><br><br><br>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><font size='4'><b><center>Jobs</center></b></font></td></tr></table>"; 
}
echo "<br><br><br><br><br>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><font size='4'><b><center>Jobs</center></b></font></td></tr></table>"; 
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><font size='4'><b><center>Jobs net you experience and money to help you on your way to discovering the mysteries of Cyberwars.</center></b></font></td></tr></table>"; 
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><a href='jobs.php' style='text-decoration: none'><font color='2bab4c'><font size='4'><b><center>Levels 1-7<br>The Beginning</center></b></font></td>";
echo "<td bgcolor='000000'><font color='2bab4c'><font size='4'><b><center>Levels 8-15<br>The Underground</b></font></td>";
echo "<td bgcolor='000000'><font color='2bab4c'><font size='4'><b><center>Levels 16-24<br>Biomorph</b></font></td>";
echo "<td bgcolor='000000'><font color='2bab4c'><font size='4'><b><center>Levels 25-34<br>Training</b></font></td>";
echo "<td bgcolor='000000'><font color='2bab4c'><font size='4'><b><center>Levels 35-45<br>First Mission</b></font></td>";
echo "<td bgcolor='000000'><font color='2bab4c'><font size='4'><b><center>Levels 45+<br>Next</b></font></td></tr></table>";

echo "<br><table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><b>Life is always boring until you are taken out of repetition of the ordinary, that is when life starts to become dangerous, and when we start to wish for the mundanity of ordinary life. Could of remain the same or it can take a stranger bint the choice is yours, will you step into the world</b></font></td></tr></table>"; 

echo "<br>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><b>The Beginning</font></b><font color='000000'>______________________________________________________________________________ </font><font color='2bab4c'>payout: $308 - $375 experience +1</font></td></tr></table>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><b>Having worked the late shift, you race to the safe of your home trying reach before you are spotted my Gene Tec's police force arresting anyone who was out after curfew. Taking a back alley to avoid the cops, you find someone lying in the way, getting out your car you go over to the person. Examining them more closely you find the person is a she and she has been shot, unable to leave her there you take her with you.</b></font></td></tr></table>"; 
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td width='50%' bgcolor='000000'><font color='2bab4c'>This job<br>requires:<br><br>1 Energy</font></td>";
if ($playerinfo3['energy'] > 0){
	echo "<td width='50%'><a href='job1.php' style='text-decoration: none'><font color='2bab4c'><b><center>Do job</center></b></font></a></td></tr></table>"; 
}else if ($playerinfo3['energy'] < 1 ){
	echo "<td width='50%'><font color='2bab4c'><b><center>You don't have enough energy to do this job</center></b></font></a></td></tr></table>"; 
}

echo "<br>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><b>Healing</font></b><font color='000000'>____________________________________________________________________________________ </font><font color='2bab4c'>payout: $343 - $413  experience +1</font></td></tr></table>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><b>Getting the young woman back to your place you lay her down on the couch, examining the wound you find that she had been shot. Grabbing your tissue replicator you seal the wound.</b></font></td></tr></table>"; 
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td width='50%' bgcolor='000000'><font color='2bab4c'>This job<br>requires:<br><br>1 Energy</font></td>";
if ($playerinfo3['energy'] > 0){
	echo "<td width='50%'><a href='job2.php' style='text-decoration: none'><font color='2bab4c'><b><center>Do job</center></b></font></a></td></tr></table>"; 
}else if ($playerinfo3['energy'] < 1 ){
	echo "<td width='50%'><font color='2bab4c'><b><center>You don't have enough energy to do this job</center></b></font></a></td></tr></table>"; 
}

if ($playerinfo3['level'] < 2){
echo "<br><br><table align='center' width='95%' border='1' cellspacing='1' bordercolor=white><tr><td bgcolor='666666'><font color='000000'><b><center>More jobs unlocked at level 2</center></font></b></font></td></tr></table>";
}else{
echo "<br>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><b>Encounter</font></b><font color='000000'>__________________________________________________________________________________ </font><font color='2bab4c'>payout: $608 - $750   experience +2</font></td></tr></table>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><b>While you are treating the young woman an intruder breaks into your home intent on taking your life, you picking up the blade from the table have only one choice defend yourself.</b></font></td></tr></table>"; 
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td width='50%' bgcolor='000000'><font color='2bab4c'>This job<br>requires:<br><br>2 Energy</font></td>";
if ($playerinfo3['energy'] > 0){
	echo "<td width='50%'><a href='job3.php' style='text-decoration: none'><font color='2bab4c'><b><center>Do job</center></b></font></a></td></tr></table>"; 
}else if ($playerinfo3['energy'] < 1 ){
	echo "<td width='50%'><font color='2bab4c'><b><center>You don't have enough energy to do this job</center></b></font></a></td></tr></table>"; 
}
}

if ($playerinfo3['level'] < 3){
echo "<br><br><table align='center' width='95%' border='1' cellspacing='1' bordercolor=white><tr><td bgcolor='666666'><font color='000000'><b><center>More jobs unlocked at level 3</center></font></b></font></td></tr></table>";
}else{
echo "<br>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><b>Healing</font></b><font color='000000'>__________________________________________________________________________________ </font><font color='2bab4c'>payout: $983 - $1,170  experience +3</font></td></tr></table>";
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td bgcolor='000000'><font color='2bab4c'><b>Getting the young woman back to your place you lay her down on the couch, examining the wound you find that she had been shot. Grabbing your tissue replicator you seal the wound.</b></font></td></tr></table>"; 
echo "<table align='center' width='95%' border='1' cellspacing='1' bordercolor=green><tr><td width='50%' bgcolor='000000'><font color='2bab4c'>This job<br>requires:<br><br>3 Energy</font></td>";
if ($playerinfo3['energy'] > 0){
	echo "<td width='50%'><a href='job2.php' style='text-decoration: none'><font color='2bab4c'><b><center>Do job</center></b></font></a></td></tr></table><br><br>"; 
}else if ($playerinfo3['energy'] < 1 ){
	echo "<td width='50%'><font color='2bab4c'><b><center>You don't have enough energy to do this job</center></b></font></a></td></tr></table><br><br>"; 
}
}
?>
And this is the page it get redirected from

Code: Select all

<?php
include_once 'connect.php';

$playerinfo="SELECT * from player where name='Bryan'";
$playerinfo2=mysql_query($playerinfo) or die("could no get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

$jobsinfo="SELECT * from jobs where name='job1'";
$jobsinfo2=mysql_query($jobsinfo) or die("could no get player stats!");
$jobsinfo3=mysql_fetch_array($jobsinfo2);

$rand1 = rand(308,375);


if ($playerinfo3['energy'] > 0){
$newenergy = $playerinfo3['energy'] - $jobsinfo3['energy'];
$updateenergy="update player set energy='$newenergy' where name='Bryan'";
  mysql_query($updateenergy) or die (mysql_error());

$newcredit = $playerinfo3['credit'] + $rand1;
$updatecredit="update player set credit='$newcredit' where name='Bryan'";
  mysql_query($updatecredit) or die (mysql_error());

$newexperience = $playerinfo3['experience'] + $jobsinfo3['experience'];
$updateexperience="update player set experience='$newexperience' where name='Bryan'";
  mysql_query($updateexperience) or die (mysql_error());

echo "<meta http-equiv='refresh' content='0;url=http://www.immortal.x10.mx/jobs.php?job=1'>";
}  
?>
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: redirect

Post by Chris »

I'd advise you start learning some object oriented programming. Making a game like this will get too complicated if you're going to run scripts like that.

You should also use headers for refreshes and not meta tags. To do this you will need to redirect before sending any data to the client. So you cannot echo anything onto a page before a redirect.

What you'll have to do is set up a small framework for your game.

If you need any help I'll help point you in the right direction but making a game like this isn't going to work out very well. Once you complete a game like this it will only become more and more work. More and more debugging and a pure pain in the ass.
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Advanced Help and Support”