putting two codes together

mysticdr

New Member
Messages
7
Reaction score
0
Points
0
i have a Site on My Adopts. and i'm using X10Hosting as a side host.

i have these two codes i got, and they work fine by themselves. but when i put them together it has an error and it says the page doesnt exist.

here is the code


Code:
 # if already visited, redirect to another page
 if ( $_COOKIE[visited] == "br549" )
 {
 header("location: [URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=tootired"]www.mysticdragonforest.myadopts.com/pages.php?page=tootired[/URL]");
 exit;
 }
 else
 {
 # Set Cookie & Expire Time
 $expire = time()+60*60*24;
 setcookie( "visited", "br549", $expire);
 }
 ?> 
$urls = array("[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=failed"]www.mysticdragonforest.myadopts.com/pages.php?page=failed[/URL]", 
              "[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=failed"]www.mysticdragonforest.myadopts.com/pages.php?page=failed[/URL]",
        "[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=failed"]www.mysticdragonforest.myadopts.com/pages.php?page=failed[/URL]",
       "[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=failed"]www.mysticdragonforest.myadopts.com/pages.php?page=failed[/URL]",
       "[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=failed"]www.mysticdragonforest.myadopts.com/pages.php?page=failed[/URL]",
       "[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=failed"]www.mysticdragonforest.myadopts.com/pages.php?page=failed[/URL]",
       "[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=failed"]www.mysticdragonforest.myadopts.com/pages.php?page=failed[/URL]",
       "[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=failed"]www.mysticdragonforest.myadopts.com/pages.php?page=failed[/URL]",
       "[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=failed"]www.mysticdragonforest.myadopts.com/pages.php?page=failed[/URL]",
       "[URL="http://www.mysticdragonforest.myadopts.com/pages.php?page=MGadopt56"]www.mysticdragonforest.myadopts.com/pages.php?page=MGadopt56[/URL]"); 
$url = $urls[array_rand($urls)]; 
header("Location: [URL]http://$url[/URL]"); 
?>




basicly when i go to this page it redirects me to a random link, but i can only view this page. once a day.

without the once a day cookie code, it works fine
example
http://mysticdragonforest.x10.mx/MGexp2.php

but when i add the cookie code
http://mysticdragonforest.x10.mx/MG.php
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
What is PHP and what is HTML in the code you posted?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
So, you don't know anything about PHP?
 

mysticdr

New Member
Messages
7
Reaction score
0
Points
0
yeah....

i'm just using it for this small thing and thats all.
do you know what the problom is? if its too complicated, ill try something else.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
<?php
# if already visited, redirect to another page
if ( $_COOKIE[visited] == "br549" )
{
header("location: www.mysticdragonforest.myadopts.com/pages.php?page=tootired");
exit;
}
else
{
# Set Cookie & Expire Time
$expire = time()+60*60*24;
setcookie( "visited", "br549", $expire);
}
?>
$urls = array("www.mysticdragonforest.myadopts.com/pages.php?page=failed",
"www.mysticdragonforest.myadopts.com/pages.php?page=failed",
"www.mysticdragonforest.myadopts.com/pages.php?page=failed",
"www.mysticdragonforest.myadopts.com/pages.php?page=failed",
"www.mysticdragonforest.myadopts.com/pages.php?page=failed",
"www.mysticdragonforest.myadopts.com/pages.php?page=failed",
"www.mysticdragonforest.myadopts.com/pages.php?page=failed",
"www.mysticdragonforest.myadopts.com/pages.php?page=failed",
"www.mysticdragonforest.myadopts.com/pages.php?page=failed",
"www.mysticdragonforest.myadopts.com/pages.php?page=MGadopt56");
$url = $urls[array_rand($urls)];
header("Location: http://$url");
?>

Make sure the code starts with the blue <?php .
Nothing else, even a space, before it.
Remove the red ?> . It is telling the PHP interpreter, "My PHP code stops here and the rest is HTML that should be output to the page"
 

mysticdr

New Member
Messages
7
Reaction score
0
Points
0
now i'm getting this error: Parse error: syntax error, unexpected $end in /home/mysticdr/public_html/MGexp3.php on line 27

here is my code


PHP:
<?php
 # if already visited, redirect to another page
 if ( $_COOKIE[visited] == "br549" )
 {
 header("location: www.mysticdragonforest.myadopts.com/pages.php?page=tootired");
 exit;
 }
 else
 {
 # Set Cookie & Expire Time
 $expire = time()+60*60*24;
 setcookie( "visited", "br549", $expire);
 }
 {
$urls = array("www.mysticdragonforest.myadopts.com/pages.php?page=failed", 
              "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
        "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=MGadopt56"); 
$url = $urls[array_rand($urls)]; 
header("Location: http://$url"); 
?>


line 27, thats the last line
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
PHP:
<?php
 # if already visited, redirect to another page
 if ( $_COOKIE[visited] == "br549" )
 {
 header("location: www.mysticdragonforest.myadopts.com/pages.php?page=tootired");
 exit;
 }
 else
 {
 # Set Cookie & Expire Time
 $expire = time()+60*60*24;
 setcookie( "visited", "br549", $expire);
 }
 {  <<<<<<<<<<<<<  BAD, EVIL, REMOVE
$urls = array("www.mysticdragonforest.myadopts.com/pages.php?page=failed", 
              "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
        "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=MGadopt56"); 
$url = $urls[array_rand($urls)]; 
header("Location: http://$url"); 
?>


:redface:
 

mysticdr

New Member
Messages
7
Reaction score
0
Points
0
PHP:
<?php
 # if already visited, redirect to another page
 if ( $_COOKIE[visited] == "br549" )
 {
 header("location: www.mysticdragonforest.myadopts.com/pages.php?page=tootired");
 exit;
 }
 else
 {
 # Set Cookie & Expire Time
 $expire = time()+60*60*24;
 setcookie( "visited", "br549", $expire);
 }
$urls = array("www.mysticdragonforest.myadopts.com/pages.php?page=failed", 
              "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
        "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=failed",
       "www.mysticdragonforest.myadopts.com/pages.php?page=MGadopt56"); 
$url = $urls[array_rand($urls)]; 
header("Location: http://$url");
?>

now it doesnt work at all. it says the page doesnt exist
http://mysticdragonforest.x10.mx/MGexp3.php
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
header("location: http://www.mysticdragonforest.myadopts.com/pages.php?page=tootired");

missing http:// on the first header call.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Note that if you pick and apply an indent style (or rather, have your editor/IDE do it for you), it would have made some of these issues very apparent.

A good editor/IDE can make all the difference. Eclipse, for example, is very powerful but has a steep learning curve. Notepad++ is much simpler and yet supports both auto-indenting and syntax highlighting (similar to what you see with
PHP:
 tags).
 
Top