php multi lang site clean url - php

I'm developing a multilang site. The content generated on the varible that passes in the url. Exemple for about us page my url is: domain.com/file.php?id=1 I got one main file and in that file the query gets the id of the selected menu.
If I change the language my url turns to domain.com/file.php?id=1&lang=en. Every time I change the language my url adds one more lang like this: domain.com/file.php?id=1&lang=en&lang=fr&lang=de&lang=en.....
in other multilang project I used this: header("location: ".$_SERVER['SCRIPT_NAME']); But the it were less dynamic pages. like this: domains.com/aboutus.php. I mean: the number of pages were static. The user cannot add or remove pages.
This time because I pass the page id in the url I tried header("location: ".$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']); but it gives an redirect cycle error every time I try to change the lang.
UPDATE
Code to select the languages:
<?php $actual= $_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"];?>
<div id="langContainer">
<span><a <?php if ($_SESSION['idLang']=='en') {echo"class='active'";}?> href="<?php echo $actual ?>&lang=en">EN</a></span>
<span><a <?php if ($_SESSION['idLang']=='fr') {echo"class='active'";}?> href="<?php echo $actual ?>&lang=fr">FR</a> </span>
<span><a <?php if ($_SESSION['idLang']=='es') {echo"class='active'";}?> href="<?php echo $actual ?>&lang=es">ES</a></span>
<span><a <?php if ($_SESSION['idLang']=='de') {echo"class='active'";}?> href="<?php echo $actual ?>&lang=de">DE</a></span>
</div>
in my session.php
if (!isset($_SESSION["idLang"]) )
$_SESSION["idLang"] = 'en';
if (#isset($_GET["lang"])){
$_SESSION["idLang"] = $_GET['lang'];
//header("location: ".$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']);
}
So my question is if there's anyway I can get my url cleaner, hidding the lang variables?
Thanks

Dynamically build query parameters, replacing exiting ones in the current URL:
<a href="...?<?php echo http_build_query(array('lang' => 'foo') + $_GET); ?>">

Related

Unable to redirect to the specific location on page in codeigniter using controller

In CodeIgniter, I want to redirect below-given link from another page to the page view called "profile.php" called by previewProfile() method in a model where "brdetails" is a name of an anchor tag which is on the page. I want the page to be scrolled on the redirected page where anchor tag is mentioned.
viewname.php [ Below given code call profile.php using previewProfile() method in model ]
<a href="<?php print base_url();?>Controller_Name/previewProfile/1/#brdetails" >
Preview
</a>
Profile.php
<a name="brdetails"></a>
use route for everything..go to application->config->routes.php in there use like this
$route['View_Function'] = "controllerName/View_Function";//normal view
$route['SaveFunction'] = " controllerName/SaveFunction";
$route['UpdateFunction'] = " controllerName/UpdateFunction";
$route['Function_Listing'] = "controllerName/Function_Listing";
//load list only $route['Function_Listing/(:num)'] ="controllerName/Function_Listing/$1";
//pagination
$route['Edit_Function/(:num)'] = "controllerName/Edit_Function/$1";
$route['Delete_Function'] = "controllerName/Delete_Function";
and then in your view
<a href="<?php print base_url();?>Edit_Function/prifle_id" >Preview</a>
try this
Try this
<a href="<?php echo base_url();?>Controller_Name/previewProfile#brdetails" >
Preview
</a>
The reason why you are not scrolling down to specific id is, you didn't include any id="brdetails" in the <a name="brdetails"></a>.
In your profile.php change the <a name="brdetails"></a> to <a id="brdetails"></a>
Hope this will help.

Conditional Back OR Close link in PHP

I've tried to find a solution to this a few different times, but keep coming up empty on a working solution. Essentially, I'm trying to find a way to have a link that is either a "close" or a "back" link in functionality. The condition being IF the use just came from another page within the same site OR if the user came into this page from an external link (search engine or otherwise).
Here's a couple links for further explanation and examples of how its NOT working:
This link shows a "list" or archive of posts: http://hillsiderancho.com/care-ministries/
Once a user goes into one of those posts (http://hillsiderancho.com/care-ministries/celebrate-recovery/), the link in the top right should read "Back", and should simply act as the browser back button, to allow the user to go back to viewing the list of pages (or possibly some other page that lead them to this post).
The other use case would be if the user comes into the post from an external site, the button should read "Close" and then point the user to the list page, not a "browser back" function that takes them away from the site again. We'd like to keep them in the site and let them explore more from the same area.
This is the code I have in place, and the "Back" button has a different functionality in nearly all of the different posts in this section... seeming as though its never hitting the "else" condition, and only coming up with some other strange referrer URL. (I just noticed a typo on my href in the "else" condition, but either way, its not getting to that page either):
<div class="post-close-btn">
<?php
$previousPage = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$url = site_url();
if ($previousPage = $url){ ?>
<a href="<?php echo $_SERVER['HTTP_REFERER']; ?>" class="primaryBtn">
<div class="inner vAlign">
<span class="text">BACK</span>
</div>
</a>
<?php } else { ?>
<a href="/care-ministries/" class="primaryBtn">
<div class="inner vAlign">
<span class="text">Close</span>
</div>
</a>
<?php } ?>
Can anyone help with this?
You are setting the variable in your if statement, not checking its value.
if ($previousPage = $url)
should be:
if ($previousPage == $url)
Here's the code that ended up working, after getting my variable corrected (thanks Robyn Overstreet)
<?php
$previousPage = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$url = site_url();
$url = preg_replace('#^https?://#', '', $url);
if ($previousPage == $url){ ?>
<a href="javascript:history.back();" class="secondaryBtn">
<div class="inner vAlign">
<span class="text">BACK</span>
</div>
</a>
<?php } else { ?>
<a href="/care-ministries/" class="secondaryBtn">
<div class="inner vAlign">
<span class="text">Close</span>
</div>
</a>
<?php } ?>
Also, I found the bit I needed to fix the URL (and get it to match up) here: https://stackoverflow.com/a/9549893/4842348
And finally, I should note that my "if" statement href was pointing back to the site homepage (duh, thats what it was told to do) - so I swapped in a basic JS history.back() - that works just fine.

Insert PHP variable in external link

The link works perfectly fine internally on the domain, just won't work for an external website. Didn't see anything in the documentation. I provided an example below. Would appreciate some insight.
<?php $user = basename($_SERVER['PHP_SELF']);?>
<a href="https://www.externaldomain.com/secure/cart/addItem.aspx?qty=1&itID=9135&PromoID=83&uid=<?php echo $user->username ?>">
Based on you comment, you must have a page url like page.php?ID=userid and you want something like this: {externalpage.com/page.php}?uid=userid
Try:
<a href="https://www.externaldomain.com/secure/cart/addItem.aspx?qty=1&itID=9135&PromoID=83&uid=<?php echo $_GET["ID"]; ?>">
Edit
Based on your last comment, try this:
<?php $user = basename($_SERVER['PHP_SELF']);?>
<a href="https://www.externaldomain.com/secure/cart/addItem.aspx?qty=1&itID=9135&PromoID=83&uid=<?php echo $user; ?>">

passing parameters to zend paginationControl partial

I have a page that displays a lot of data, including Zend_Paginator.
The page action is /po/fetch?id=someID.
what i want to do is to pass the "id" parameter to zend paginationControl so the pagination links will be something like /po/fetch?id=someID&page=somePage. unfortunally i can't find anywhere explanation on how i can pass that parameter to the paginationControl.
my call to paginationControl:
echo $view->paginationControl($paginator, 'Sliding',$control, $params);
where $params = array('id' => someID
and my pagination partial is:
First
< Previous
<?php
foreach($this->pagesInRange as $page) {
?>
.$page. | ;
<?php
}
?>
Next >
Last
and I want $url to be of the specified form.
$this->id
Hey Try this, It will surely work.....
<a href="<?php echo $this->url(array('page' => $page,'id'=>'1')); ?>">
<?php echo $page; ?>
</a>
Here 1 is given as the id you have to pass the id you want.......
Like
<a href="<?php echo $this->url(array('page' => $page,'id'=>$param['id'])); ?>">
<?php echo $page; ?>
</a>
Your example code doesn't show how $url is populated, but you really should be using the URL ViewHelper.
So, for example - your previous link would become:
< Previous
This will return a proper URL to the current page with the page parameter set to $this->previous. So if the current url is /users/view?foo=bar&page=5, the above code would output /users/view?foo=bar&page=4 for the previous link. Notice how any query parameters that are already present are preserved.
So, if the id parameter is already present on the URL showing your paginator, the above code will "just work". However, if you still need to add the id parameter, you can do so like this:
< Previous
To continue from our previous example, this code would output the following url: /users/view?foo=bar&page=4&id={someId}
Here is the reference documentation for the URL ViewHelper:
url($urlOptions, $name, $reset):
Creates a URL string based on a named
route. $urlOptions should be an
associative array of key/value pairs
used by the particular route.
One last note - the $reset (third) parameter of the URL ViewHelper will come in very handy. The default behavior is to preserve any query parameters of the current request but calling $this->url(array(), 'default', true) with true for the $reset parameter will basically remove all parameters except for the ones you specify in $urlOptions.
I have gone through the same issue so I have used code given below in partial paginator.
I have created a function in paginator partial view file(control.phtml) or may be different.
function queryStr($p){
$params = $array = Zend_Controller_Front::getInstance()->getRequest()->getQuery();
$params['page']=$p;
$str='?';
foreach($params as $k=>$v){
if($v)
$str .= $k.'='.$v.'&';
}
return $str;
}
Now for links I am using code given below.
<a href="<?php echo queryStr($page); ?>">
Instead of
<a href="<?php echo $this->url(array('page' => $page)); ?>">
I am sure it will be helpful to others as well.

How to get the URL of the current page with the title and post it to Digg?

We have a Joomla site and have purchased a template from Gavick.
I need to change the code which is part of a template we have purchased.
If I hardcode the parameters associated to the Digg button as follows then I am taken to Digg's website submission link form and can add the details.
The current code in the template is as follows:
<?php if($this->template->params->get("icon2", 1) == 1) : ?>
<a href="<?php echo $this->template->params->get("icon2_link", ''); ?>"
class="social_icon" id="social_icon2" target="_blank">Digg</a><?php endif; ?>
What I need to do is get the URL of the current page along with the title and post this to Digg.
Never used Joomla but...
<?php if($this->template->params->get("icon2", 1) == 1) : ?>
<a href="http://digg.com/submit?Url=<?php echo $_SERVER["REQUEST_URI"]?>&title=<?=mainframe->getPageTitle()?>&no_mobile=1"
class="social_icon" id="social_icon2" target="_blank">Digg</a><?php endif; ?>
I don't know variable for title.

Categories