Forum Moderators: coopster

Message Too Old, No Replies

parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '(' on

on line 9 of red.php

         

rudraksh

1:34 pm on Jul 10, 2005 (gmt 0)



hi! phpfreaks,
I wanted this php redirection script to work on my site -- as aredirection script to hidden links within the php file which is being called by the the above mentioned html file.

But I am getting this error when I click on links
5
6
7
in the red.html page
--------------------
i am posting the full red.php script. Please help me debug this or please if you can, do it for me(post reply).

<?php
/*
?id=any number
*/

/* url to be displayed */
$pages = array(
\'5\' => [\'http://www.nasa.gov\'],
\'6\'=> [\'http://www.example.com/home.css\'],
\'7\'=> [\'http://www.warnerbrothers.com\'],
);

//if the file exist, and is in the array it will display the url.
if(array_key_exists($_GET[\'id\'], $pages))
{
foreach($pages as $id => $name) {
if($_GET[\'id\'] == $id && file_exists($name)) {
include $name;
}
}
}

else {

//We will now display the home page, but if u enter the wrong id it will display this page.
include(\"http://www.example.com/index.html\");
}
?>

---------------------

[edited by: jatar_k at 3:50 pm (utc) on July 10, 2005]
[edit reason] removed urls [/edit]

dreamcatcher

1:54 pm on Jul 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World rudraksh. :)

No need for escaping all those apostrophes and also the last value in the array has no comma after it. Try:

$pages = array(
5 => 'http://www.nasa.gov',
6 => 'http://www.example.com/home.css',
7 => 'http://www.warnerbrothers.com'
);

dc

[edited by: jatar_k at 3:50 pm (utc) on July 10, 2005]

rudraksh

2:56 pm on Jul 10, 2005 (gmt 0)



Dear dreamcatcher,
I am extremely grateful for your reply but after doing what you have said I am still getting the error as a blank page and it is not redirecting but showing a white blank page!
----------------------

Thank you
RH

----------------------
<?php
/*
?id=any number
*/

/* url to be displayed */
$pages = array(
5 => 'http://www.nasa.gov',
6 => 'http://www.example.com/home.css',
7 => 'http://www.warnerbrothers.com',
);

//if the file exist, and is in the array it will display the url.
if(array_key_exists($_GET['id'], $pages))
{
foreach($pages as $id => $name) {
if($_GET['id'] == $id && file_exists($name)) {
include $name;
}
}
}

else {

//We will now display the home page, but if u enter the wrong id it will display this page.
include("http://www.example.com/index.html");
}
?>

[edited by: jatar_k at 3:50 pm (utc) on July 10, 2005]

john_k

3:14 pm on Jul 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



7 => 'http://www.warnerbrothers.com',

Remove the comma at the end of the last element.

rudraksh

3:22 pm on Jul 10, 2005 (gmt 0)



It's still not working. I have removed the comma at the end of the URL!

Help me it's getting on my nerves as to why this prob. is recurring. Its not getting redirected.

Sincerely
RH

rudraksh

3:26 pm on Jul 10, 2005 (gmt 0)



HERE IS LAST UPDATED PHP FILE...!
---------------------------------
<?php
/*
?id=any number
*/

/* url to be displayed */
$pages = array(
5 => 'http://www.nasa.gov',
6 => 'http://www.example.com/home.css',
7 => 'http://www.warnerbrothers.com'
);

//if the file exist, and is in the array it will display the url.
if(array_key_exists($_GET['id'], $pages))
{
foreach($pages as $id => $name) {
if($_GET['id'] == $id && file_exists($name)) {
include $name;
}
}
}

else {

//We will now display the home page, but if u enter the wrong id it will display this page.
include("http://www.example.com/index.html");
}
?>

[edited by: jatar_k at 3:51 pm (utc) on July 10, 2005]

john_k

3:43 pm on Jul 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you "clean up" the code for posting? Specifically, the error message says line 9. Is that the actual line number?

Also, the include function should have parens, and that would be in step with the error text. So

include $name;

should probably be

include($name);

rudraksh

3:55 pm on Jul 10, 2005 (gmt 0)



Thanks,

But after putting include($name); also it's still not redirecting. Please help me it's very urgent...

But thanks anyway....waiting

jatar_k

3:59 pm on Jul 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



instead of include why not use header [php.net]?

coopster

5:28 pm on Jul 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Because include() is a special language construct, parentheses are not needed around its argument. They won't hurt, but aren't necessary. I always use quotation marks though.

The first thing I would do is start exiting the script, line by line until I figured out how far it is getting before it fails or doesn't work the way I expect it too. Usually that is a logic statement, in this case more than likely your if statement. See if the id is in the $_GET superglobal array, and then take a closer look at that file_exists function return value.

jatar_k is correct here as well. If you truly want to redirect you should be using header [php.net], not include.

rudraksh

4:50 am on Jul 11, 2005 (gmt 0)



This is what i have done and i am still gettinga blank page without redirection. I am new to php, so please edit the code for me and send it to me if possible to my mail address or please post it totally as I have done.

Thanks
RH
-------------------
<?php
/*
?id=any number
*/

/* url to be displayed */
$pages = array(
5 => 'http://www.nasa.gov',
6 => 'http://www.example.com/a2zdownload_home.css',
7 => 'http://www.warnerbrothers.com'
);

//if the file exist, and is in the array it will display the url.
if(array_key_exists($_GET['id'], $pages))
{
foreach($pages as $id => $name) {
if($_GET['id'] == $id && file_exists($id)) {
include($name);
}
}
}

else {

//We will now display the home page, but if u enter the wrong id it will display this page.
include("http://www.example.com/index.html");
}
?>

[edited by: jatar_k at 4:52 am (utc) on July 11, 2005]
[edit reason] no personal urls thanks [/edit]

dreamcatcher

7:42 am on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With all due respect rudraksh, I don`t think you have been reading the previous suggestions. As jatar_k mentioned, use the header function.

Try something simple like this:

$id = $_GET['id'];

$pages = array(
5 => 'http://www.nasa.gov',
6 => 'http://www.example.com/a2zdownload_home.css',
7 => 'http://www.warnerbrothers.com'
);

if ($id==5 ¦¦ $id==6 ¦¦ $id ==7)
{
header("Location: {$pages[$id]}");
}
else
{
header("Location: http://www.example.com/index.html");
}

That looks like all you need.

dc

rudraksh

8:40 am on Jul 11, 2005 (gmt 0)



PLEASE CHECK THIS ERROR OUT CAME AS PER YOUR SOLUTION...
--------------------------------------------
Warning: Unexpected character in input: ' ' (ASCII=11) state=1 in /usr/www/virtual/kamranjilani123/www.example.com/red1.php on line 17

Warning: Unexpected character in input: ' ' (ASCII=11) state=1 in /usr/www/virtual/kamranjilani123/www.example.com/red1.php on line 17

Warning: Unexpected character in input: ' ' (ASCII=11) state=1 in /usr/www/virtual/kamranjilani123/www.example.com/red1.php on line 17

Warning: Unexpected character in input: ' ' (ASCII=11) state=1 in /usr/www/virtual/kamranjilani123/www.example.com/red1.php on line 17

Parse error: parse error, unexpected T_STRING in /usr/www/virtual/kamranjilani123/www.example.com/red1.php on line 18

[edited by: jatar_k at 4:22 pm (utc) on July 11, 2005]
[edit reason] no personla urls thanks [/edit]

rudraksh

8:43 am on Jul 11, 2005 (gmt 0)



THIS IS THE ACTUAL CODE
-----------------------
<?php
$id = $_GET['id'];
$pages = array(
5 => 'http://www.nasa.gov',
6 => 'http://www.example.com/home.css',
7 => 'http://www.warnerbrothers.com'
);
if ($id==5 ¦¦ $id==6 ¦¦ $id ==7)
{
header("Location: {$pages[$id]}");
}
else
{
header("Location: http://www.example.com/index.html");
}
?>

[edited by: jatar_k at 4:24 pm (utc) on July 11, 2005]
[edit reason] no personal urls thanks [/edit]

dreamcatcher

9:08 am on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you copying and pasting from the forum? Make sure you type the pipes ( ¦ ) in your text editor. Try that.

[edit]It is the pipes. The code should be ok apart from that.

rudraksh

11:01 am on Jul 11, 2005 (gmt 0)



THANKS DUDES WE MADE IT ... :-)
---------------------------------
please visit <snip> and click on those links and they will take you to separate sites respectively by numbers as specified in the php program...we did a good job...Thanks WEBMASTERWORLD FOR THIS AND LET'S MOVE ON NOW...!

sincerely
RH

[edited by: jatar_k at 4:25 pm (utc) on July 11, 2005]
[edit reason] no personal urls thanks [/edit]