Current location: Hot Scripts Forums » Programming Languages » PHP » Help with code


Help with code

Reply
  #1 (permalink)  
Old 01-31-10, 05:59 AM
marioliveira marioliveira is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes Help with code

Sorry, I'vce looked into code help but it's not easy for a PHP beginner to reach conclusions. I have a PHP file which is part of a Joomla component that displays amnong other icons, one to enable the user to sign in for RSS feeds from my site. The respective code is:

Code:
if ($tt == "yes")echo '<a id="l8" target="_blank" rel="nofollow" href="'.$url.'/index.php?format=feed&type=rss&title=&lang=en"><img title="RSS Feed" border="0" src="modules/mod_nice_social_bookmark/icons/rss_'.$iset.'_'.$isize.'.png" alt="RSS Feed" /></a>&nbsp;';
what it does, I think, is opening a screen where the RSS signup shows. The url is, I think, picked up by a piece of code at the beginning:

Code:
$url = "http://".$_SERVER['HTTP_HOST'] . getenv('REQUEST_URI');
What happens is my site is bilingual, so when you digit the URL http:///www.marioliveira.net this script work ok. But when a lkanguage is selected and the URL become something like http://www.marioliveira.net/index.php&lang=pt(or en) it does not work.

I was dreaming of changing this in the following way:
- The script would work with either of the URLs, i.,e. with or without the index.php&lang=[language]
- The displayed news on the appearing RSS subscription screen being in Portuguese or in English according to the selection.

Probably for a lot of people here this may be straightforward, but to me...

Tnks a lot for any help anyone can give. I am attaching the file in case it's easier to 'read through' it as a whole.
Attached Files
File Type: txt php file.txt (3.1 KB, 83 views)
Reply With Quote
  #2 (permalink)  
Old 01-31-10, 05:49 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
http://www.marioliveira.net/index.php&lang=pt
Code:
http://www.marioliveira.net/index.php&lang=pt
Should be:

Bem vindo(a) ao site da Lígia e do Mário
Code:
http://www.marioliveira.net/index.php?lang=pt
Reply With Quote
  #3 (permalink)  
Old 01-31-10, 06:32 PM
marioliveira marioliveira is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Help with code

You're right, I misspelled it, it's indeed as you say
www.marioliveira.net/index.php?lang=pt(or en)

It is with this URl that it doesn't work
Reply With Quote
  #4 (permalink)  
Old 01-31-10, 09:00 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
It works for me if I put in:
Code:
www.marioliveira.net/index.php?lang=pt

//or

www.marioliveira.net/index.php?lang=en
Reply With Quote
  #5 (permalink)  
Old 01-31-10, 09:51 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
This works (query string was cleaned up a bit):

You can try:

PHP Code:

/* You can test with */

$url "http://".$_SERVER['HTTP_HOST'] . $_SERVER['QUERY_STRING'];

/* You should run with something like this: */
// http://us3.php.net/manual/en/function.parse-str.php

/* Get the query string values into an array */
parse_str($_SERVER['QUERY_STRING'],$aValues);  

/* Loop through the array, ensuring the values are valid. */
/* Crash for invalid values, discard invalid parameters.   Discard title (unless you sanitize it) */
$sParms='';
foreach (
$aValues as $k => $v)
{
  switch (
$k)
  {
    case 
'lang': if (!in_array($v,array('pt','en'))) exit();
      break;
    case 
'format': if ($v != 'feed') exit();
      break;
    case 
'type': if ($v != 'rss') exit();
      break;
    case 
'title'$v='';
      break;
    default: exit(); 
/* Invalid parameter */
  
}
  if (
$sParms != ''$sParms.='&';
  
$sParms.=$k.'='.$v;
}
$url "http://".$_SERVER['HTTP_HOST'] .$sParms
Not tested.
Reply With Quote
  #6 (permalink)  
Old 01-31-10, 11:17 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Might want to add this to the last $url line
PHP Code:

$url "http://".$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?' $sParms

Last edited by Jcbones; 01-31-10 at 11:19 PM. Reason: wrong variable
Reply With Quote
  #7 (permalink)  
Old 02-01-10, 06:43 AM
marioliveira marioliveira is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Still not working

Hi and thanks for your patience. It doesn't work yet. When I click on the rss feed it goes to the following URL:
Code:
http://www.marioliveira.netlang=pt/index.php?format=feed&type=rss&title=
if I change the URL to
Code:
http://www.marioliveira.net/index.php?lang=en&format=feed&type=rss&title
=

it displays ok. So it is not only a question of inserting the '&' after index.php and of replacing the '?' before format(etc) by '&', but also changing their order in the sequence. For my almost to none knowledge, despite of several attemps, it's too much

Last edited by marioliveira; 02-01-10 at 06:47 AM.
Reply With Quote
  #8 (permalink)  
Old 02-01-10, 12:52 PM
marioliveira marioliveira is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
New trial

If I replace the URL line for the second one you suggested, then


1. If I choose the language with the language selecor, i.e. something like site URL
Code:
http://www.marioliveira.net/index.php?lang=xx
then choosing RSS feeds I obtain the URL
Code:
http://www.marioliveira.net/index.php?lang=xx/index.php?format=feed&type=rss&title=
]

i.e. there is an /index.php extra.

2. If I don't choose the language, so having an URL like
Code:
http://www.marioliveira.net
then the RSS feed button will put as URL
Code:
http://www.marioliveira.net/index.php?/index.php?format=feed&type=rss&title=
so in this case the extra /index.php is still there, and there is no '?lang=xx' anywhere

Thanks
Reply With Quote
  #9 (permalink)  
Old 02-01-10, 02:40 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I think if you add Jcbones's code to mine it should work.
Reply With Quote
  #10 (permalink)  
Old 02-01-10, 03:41 PM
marioliveira marioliveira is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Still unsuccessful

Quote:
Originally Posted by wirehopper View Post
I think if you add Jcbones's code to mine it should work.
No, what I was trying to say in my latest message is that putting both codes together I still dont succeed. Here's what I have non in my php mopdified file, with the results I described above:

Code:
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body>

<?php

// no direct access

//defined( '_VALID_MOS' ) or die( 'Restricted access' );

//$url = "http://".$_SERVER['HTTP_HOST'] . getenv('REQUEST_URI'); 



/* You can test with */ 
$url = "http://".$_SERVER['HTTP_HOST'] . $_SERVER['QUERY_STRING']; 

/* You should run with something like this: */ 
// http://us3.php.net/manual/en/function.parse-str.php 

/* Get the query string values into an array */ 
parse_str($_SERVER['QUERY_STRING'],$aValues);   

/* Loop through the array, ensuring the values are valid. */ 
/* Crash for invalid values, discard invalid parameters.   Discard title (unless you sanitize it) */ 
$sParms=''; 
foreach ($aValues as $k => $v) 
{ 
  switch ($k) 
  { 
    case 'lang': if (!in_array($v,array('pt','en'))) exit(); 
      break; 
    case 'format': if ($v != 'feed') exit(); 
      break; 
    case 'type': if ($v != 'rss') exit(); 
      break; 
    case 'title': $v=''; 
      break; 
    default: exit(); /* Invalid parameter */ 
  } 
  if ($sParms != '') $sParms.='&'; 
  $sParms.=$k.'='.$v;
} 
/// $url = "http://".$_SERVER['HTTP_HOST'] .$sParms;  
$url = "http://".$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?' . $sParms; 




$isize = $params->get('isize');

$iset = $params->get('iset');

$iposition = $params->get('iposition');



echo '<div class="nsb_container" align="'.$iposition.'">';

echo '<link rel="stylesheet" type="text/css" href="modules/mod_nice_social_bookmark/css/nsb.css" />';

$tt = $params->get('s1', 'yes');

if ($tt == "yes")echo '<a id="l1" target="_blank" rel="nofollow" href="http://www.facebook.com/sharer.php?u='.$url.'&title="><img title="Facebook" border="0" src="modules/mod_nice_social_bookmark/icons/facebook_'.$iset.'_'.$isize.'.png" alt="Facebook" /></a>&nbsp;';

$tt = $params->get('s2', 'yes');

if ($tt == "yes")echo '<a id="l2" target="_blank" rel="nofollow" href="http://www.myspace.com/Modules/PostTo/Pages/?l=3&u='.$url.'&title="><img title="MySpace" border="0" src="modules/mod_nice_social_bookmark/icons/myspace_'.$iset.'_'.$isize.'.png" alt="MySpace" /></a>&nbsp;';

$tt = $params->get('s3', 'yes');

if ($tt == "yes")echo '<a id="l3" target="_blank" rel="nofollow" href="http://twitter.com/home?status='.$url.'&title="><img title="Twitter" border="0" src="modules/mod_nice_social_bookmark/icons/twitter_'.$iset.'_'.$isize.'.png" alt="Twitter" /></a>&nbsp;';

$tt = $params->get('s4', 'yes');

if ($tt == "yes")echo '<a id="l4" target="_blank" rel="nofollow" href="http://digg.com/submit?phase=2&amp;url='.$url.'&title="><img title="Digg" border="0" src="modules/mod_nice_social_bookmark/icons/digg_'.$iset.'_'.$isize.'.png" alt="Digg" /></a>&nbsp;';

$tt = $params->get('s5', 'yes');

if ($tt == "yes")echo '<a id="l5" target="_blank" rel="nofollow" href="http://del.icio.us/post?url='.$url.'&title="><img title="Delicious" border="0" src="modules/mod_nice_social_bookmark/icons/delicious_'.$iset.'_'.$isize.'.png" alt="Delicious" /></a>&nbsp;';

$tt = $params->get('s6', 'yes');

if ($tt == "yes")echo '<a id="l6" target="_blank" rel="nofollow" href="http://www.stumbleupon.com/submit?url='.$url.'&title="><img title="Stumbleupon" border="0" src="modules/mod_nice_social_bookmark/icons/stumbleupon_'.$iset.'_'.$isize.'.png" alt="Stumbleupon" /></a>&nbsp;';

$tt = $params->get('s7', 'yes');

if ($tt == "yes")echo '<a id="l7" target="_blank" rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk='.$url.'&title="><img title="Google Bookmarks" border="0" src="modules/mod_nice_social_bookmark/icons/google_'.$iset.'_'.$isize.'.png" alt="Google Bookmarks" /></a>&nbsp;';

$tt = $params->get('s8', 'yes');

if ($tt == "yes")echo '<a id="l8" target="_blank" rel="nofollow" href="'.$url.'/index.php?format=feed&type=rss&title="><img title="RSS Feed" border="0" src="modules/mod_nice_social_bookmark/icons/rss_'.$iset.'_'.$isize.'.png" alt="RSS Feed" /></a>&nbsp;';

echo '</div><div style="clear:both;"></div>';

?>

</body>

</html>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Match code in link with code with one in file and extract line peuplarchie PHP 3 10-24-09 01:23 AM
Freeze columns in a table Rita Negi Script Requests 1 09-01-09 08:23 AM
OTO Redirect Code Placement Tony S. HTML/XHTML/XML 7 07-25-09 09:31 AM
Need captcha for html+php contact form sujata_ghosh PHP 6 03-22-09 03:46 PM
Explanation of Code... Please davidk19380 Perl 1 02-26-06 01:50 PM


All times are GMT -5. The time now is 08:09 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.