Jump to content

Can someone tell me what the error is in this PHP '$_GET if else' code


james909

Recommended Posts

Can someone tell me what the error is in this PHP '$_GET if else' code

 

	<!-- /debughtml -->
</div>
<br />
<?php
if (isset($_GET['title']) && $_GET['title'] == 'Main_Page,Community_portal,Current_events,Special:RecentChanges,Help:Contents,Special:WhatLinksHere/Help:Contents,Special:Upload,Special:SpecialPages,itsmywiki.com:Privacy_policy,itsmywiki.com:About,itsmywiki:General_disclaimer,Special:Preferences,Special:Watchlist,Special:Contributions/itsmywiki.com,Special:UserLogout&returnto=Special%3AContributions%2F$,User:$,User_talk:$') {
// do nothing
} else {
if (isset($_GET['action']) && $_GET['action'] == 'edit,history') {
// do nothing
} else { ?>
<center><div class="fb-comments" data-width="800" data-num-posts="100" data-colorscheme="dark"></div></center>
<?php } ?>
<!-- /bodyContent -->

 

this code is causing a syntax error further down the page, and i cant figure out what the problem is?

Edited by james909
Link to comment
Share on other sites

I usually try and separate the logic from the html. For the current code it would be something like.

 

<?php
//logic goes here
if (isset($_GET['action']) && $_GET['action'] = "myaction")
{
$action = "";
}
else
{
$action = "html string";
}
?>
<div>
<?php echo $action; ?>
</div>

Edited by pmccall2
Link to comment
Share on other sites

thanks for all the help

 

akkay47, it is showing "Parse error: syntax error, unexpected T_PRIVATE in /home/acc/public_html/itsmywiki.com/skins/Vector.php on line 268" in the web-browser

 

 

 

i changed the html line using 'echo' to

 

 

} else {
echo '<center><div class="fb-comments" data-width="800" data-num-posts="100" data-colorscheme="dark"></div></center>';
} ?>

 

and it is still showing a syntax error

Edited by james909
Link to comment
Share on other sites

thank you TOA! it was the missing closing braket }

 

the syntax error has gone away and the page loads

 

 

the code that i wrote is still not working as it should

the url 'http://itsmywiki.com/index.php?title=Main_Page'

is displaying the facebook comment code, and i am trying to use the title variable in the the if code to avoid the Main_Page (along with the other pages) displaying the facebook comments

Link to comment
Share on other sites

Most likely, your desired titles and actions are being treated as strings; that's what it looks like to me. You either need to test for each one, or make an array out of the values and use in_array.

 

Ex:

$allowed = array('edit','history');
if (in_array($_GET['action'], $allowed)) {
// show comment code
}

 

Something like that...

Link to comment
Share on other sites

thank you for the reply TOA, i have changed the code to:

 

 

<!-- /debughtml -->
</div>
           <br />
           <?php
$allowed = array('Main_Page','Community_portal','Current_events','Special:RecentChanges','Help:Contents','Special:WhatLinksHere/Help:Contents','Special:Upload,Special:SpecialPages','itsmywiki.com:Privacy_policy','itsmywiki.com:About','itsmywiki:General_disclaimer','Special:Preferences,Special:Watchlist','Special:Contributions/itsmywiki.com','Special:UserLogout&returnto=Special%3AContributions%2F$','User:$,User_talk:$');
if (in_array($_GET['action'], $allowed)) {
   // do nothing
} else {
$allowed = array('edit','history');
if (in_array($_GET['action'], $allowed)) {
// do nothing
}
else {
echo '<center><div class="fb-comments" data-width="800" data-num-posts="100" data-colorscheme="dark"></div></center>';
}
}?>
<!-- /bodyContent -->

 

and the facebook comments is still appearing on all the URLs :confused: :confused:

 

example of the URLs:

 

http://itsmywiki.com/index.php?title=Page_1 (i want the facebook comments to appear here)

http://itsmywiki.com/index.php?title=Page_1&action=edit (i dont want the facebook comments to appear here)

http://itsmywiki/index.php?title=Main_Page (i dont want the facebook comments to appear here)

 

but the facebook comments is currently appearing on every site page

Link to comment
Share on other sites

Also, check out this indented version

$banned = array('Main_Page','Community_portal','Current_events','Special:RecentChanges','Help:Contents','Special:WhatLinksHere/Help:Contents','Special:Upload,Special:SpecialPages','itsmywiki.com:Privacy_policy','itsmywiki.com:About','itsmywiki:General_disclaimer','Special:Preferences,Special:Watchlist','Special:Contributions/itsmywiki.com','Special:UserLogout&returnto=Special%3AContributions%2F$','User:$,User_talk:$');
$allowed = array('edit','history');
if (in_array($_GET['title'], $banned)) {
 // do nothing
} else {
if (in_array($_GET['action'], $allowed)) {
// do nothing
}
else {
echo '<center><div class="fb-comments" data-width="800" data-num-posts="100" data-colorscheme="dark"></div></center>';
}
}

 

if the $_GET['title'] is in that array, you do nothing. Try negating that (!in_array())

Edited by TOA
Link to comment
Share on other sites

a further question, what is the command for any text, like the '*' in google and file searches

 

so that pages with:

title=User_talk:joe_bloggs

title=User_talk:tom

title=User_talk:dick

title=User_talk:harry

 

are all covered

 

i tried 'User_talk*' and 'User_talk$' and didnt work

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.