Jump to content

[SOLVED] Display HTML Code if URL = ""


luke777

Recommended Posts

Hi there,

 

Im Stuck! I have a website monstergamez.net

 

Which has 4,000 games on but unfortunatly im unable to edit individual game pages because its based on game.php.

 

Basically i need some php code to put into game.php that will recognise the url and act on it.

 

For example I need to display an advert on http://www.monstergamez.net/index.php?params=game/991/Nightmare-House/

 

So the php code would have to be somthing like this :

 

If remote url = "http://www.monstergamez.net/index.php?params=game/991/Nightmare-House/"

then

DISPLAY AD CODE

end if

 

I hope this is clear enough for someone to give me an answer!

 

Thanks Luke!

 

 

Link to comment
Share on other sites

maybe you should have a table in your database for adverts with an id corresponding to a game, then on your game.php have a statement which checks if an advert exists for that game. if it does it outputs it, otherwise it doesn't.

Link to comment
Share on other sites

what about a switch?

 

<?php
switch($_SERVER['PHP_SELF']){
case 'Bat-In-Nightmare.html':
	//HTML CODE HERE
break;
case 'othergame.html':
	//HTML CODE HERE
break;
case 'anothergame.html':
	//HTML CODE HERE
break;
default:
		//HTML CODE HERE (probably leave blank to not show anything)
break;
}
?>

Link to comment
Share on other sites

I placed this code in the game.php file

<?php
switch($_SERVER['PHP_SELF']){
case 'Bat-In-Nightmare.html':
	//HTML CODE HERE
break;
case 'game/9999398/Bat-In-Nightmare.html':
	//yo yo yo
break;
case 'anothergame.html':
	//HTML CODE HERE
break;
default:
hello
break;
}
?>

 

Nothing happens could someone provide an alternative code or explain this one better ?

 

Thanks Luke.

Link to comment
Share on other sites

change the comments to some code.. such as:

<?php
switch($_SERVER['PHP_SELF']){
case 'Bat-In-Nightmare.html':
	echo 'this is bat in nightmare';
break;
case 'game/9999398/Bat-In-Nightmare.html':
	echo 'so is this';
break;
case 'anothergame.html':
	echo 'this is another game';
break;
default:
hello
break;
}
?>

just place whatever code you want to happen in those parts.

Link to comment
Share on other sites

I have done this ....

 

This is the current code in game.php (the template file for all game pages)

 

<?php
switch($_SERVER['PHP_SELF']){
case 'http://www.monstergamez.net/game/9999398/Bat-In-Nightmare.html':
	echo 'so is this';
break;
case 'anothergame.html':
	echo 'this is another game';
break;
default:

break;
}
?>

 

case = "http://www.monstergamez.net/game/9999398/Bat-In-Nightmare.html" because i already tryed just

	case 'game/9999398/Bat-In-Nightmare.html':

 

Nothing is showing up on http://www.monstergamez.net/game/9999398/Bat-In-Nightmare.html please could someone help me :(.... i know barely any php and if you read the posts above you will understand my problem  :-\

 

Thanks Luke.

 

 

Link to comment
Share on other sites

Yes i have tryed this but nothing shows on that page!

 

Current code on game.php =

 

<?php

switch($_SERVER['PHP_SELF']){

case '/game/9999398/Bat-In-Nightmare.html':

echo 'so is this';

break;

case 'anothergame.html':

echo 'this is another game';

break;

default:

break;

}

?>

 

but still nothing on http://www.monstergamez.net/game/9999398/Bat-In-Nightmare.html

 

If i place code in between

default:

break;

 

then it works.... but thats for every page.

 

help!

 

Luke.

Link to comment
Share on other sites

try this way ok.

 

<?php ob_start();?>
<html>

<title>My Games Page</title>

<head></head>

<body><center>My Games<hi></center>

<br>
<br>

<center>

<table border="4" bordercolor="black">
<tr>
<td>
<a href="<?php $_SERVER['PHP_SELF']?>?cmd=game1">Game 1 </a>
</td>
<td>
<a href="<?php $_SERVER['PHP_SELF']?>?cmd=game2">Game 2 </a>
</td>
<td>
<a href="<?php $_SERVER['PHP_SELF']?>?cmd=game3">Game 3 </a>
</td>
<td>
<a href="<?php $_SERVER['PHP_SELF']?>?cmd=game4">Game 4 </a>
</td>
<td>
<a href="<?php $_SERVER['PHP_SELF']?>?cmd=game5">Game 5 </a>
</td>
</tr>
</table>

</center>

</body>

</html>

<?php

if($_GET['cmd']=="game1"){

header("location: http://www.google.com");
}

if($_GET['cmd']=="game2"){

header("location: http://www.yahoo.com");
}

if($_GET['cmd']=="game3"){

header("location: http://www.msn.com");
}

if($_GET['cmd']=="game4"){

header("location: http://www.ask.com");
}
if($_GET['cmd']=="game5"){

header("location: http://www.yell.com");
}
?>

<?php ob_flush();?>

Link to comment
Share on other sites

echo $_SERVER['PHP_SELF'];

 

Shows

/index.php

 

This may be relevant : .htacess contents

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^monstergamez.net [NC] 
RewriteRule ^(.*)$ http://www.monstergamez.net/$1 [L,R=301]

RewriteEngine on
RewriteRule ^(.*)\.html$ index.php?params=$1 [L]

Redirect 301 http://monstergamez.net http://www.monstergamez.net

 

Link to comment
Share on other sites

/index.php

?

Is that from the page which displays the games?

If so what code do you have to display the right game?

 

I don't think any of those htaccess variables would effect it.. apart from maybe the .php to .html one.

Link to comment
Share on other sites

What is the page name that has all the code to display each game? wasn't it game.php?

try the

echo $_SERVER['PHP_SELF'];

in game.php

 

You'd most likely have some $_GET data in the url as well.. such as

game.php?id=314, but only when a game is selected

 

 

Link to comment
Share on other sites

the switch I've given you is a neater way of using lots of if's, giving more flexibility to add more text/html to other pages if needed.

Think of each case: as an if(){ and the break; as the closing bracket }

The switch() part checks a certain variable and the cases are the value of that variable..

so instead of having:

<?php
if($_SERVER['PHP_SELF'] == '/game.php'){
echo 'some text';
}elseif($_SERVER['PHP_SELF'] == '/index.php'){
echo 'some other text';
}
?>

you can use:

switch($_SERVER['PHP_SELF']){
case '/game.php':
	echo 'some text';
break;
case '/index.php':
	echo 'some other text';
break;
default:

break;
}

 

the default: part is what it should echo/do if switch($_SERVER['PHP_SELF']) doesn't equal anything in any of the cases.

Link to comment
Share on other sites

Hi

 

Briefly reading this topic it seems you are putting the code given by other members into "game.php" when on the first post it suggests that you should be putting the code on "index.php".

 

This is the real URL:

 

http://www.monstergamez.net/index.php?params=game/991/Nightmare-House/

 

With use of mod-rewrite you are making the URL appear like:

 

http://www.monstergamez.net/game/991/Nightmare-House.html

 

The fact that game appears after the domain name when using mod-rewrite is where I think you are going wrong. You are editing "game.php" when infact you should be editing "index.php".

 

A simple piece of code on "index.php" should work:

 

<?php

$URL = "http://www.monstergamez.net/".$params."";
$URL = rtrim($URL, "/") . ".html";

switch($URL) {
case 'http://www.monstergamez.net/game/991/Nightmare-House.html': //If this URL is in the browser...
echo '<b>Put your ad for the game "Nightmare House" here...</b>'; // ... Display this HTML.
break;

case 'http://www.monstergamez.net/game/9999398/Bat-In-Nightmare.html': //If this URL is in the browser...
echo '<b>Put your ad for the game "Bat In Nightmare" here...</b>'; // ... Display this HTML.
break;

default:
echo 'Error!';
}

?>

 

Let me know how you get on..

 

Chris.

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.