Some of my Pages gives a correct shorten URL back but some of the will not. Even they are shorten at Yourls. I can see it at the Admin Panel.
This is the debug of a Page with shorten URL
{"status":"fail","code":"error:url","url":{"keyword":"09266","url":"http:\/\/domain.com\/LilyPad-Arduino-328-Main-Board","title":"LilyPad Arduino 328 Main Board","date":"2015-02-12 00:35:39","ip":"xxx.xxx.xxx","clicks":"0"},"message":"http:\/\/domain.com\/LilyPad-Arduino-328-Main-Board already exists in database","title":"LilyPad Arduino 328 Main Board","shorturl":"http:\/\/doma.in\/09266","statusCode":200,"qrcimg":"http:\/\/doma.in\/user\/plugins\/inline-qrcode\/images\/qrccf6f0d99893974288d48676d9cdbd51a.png","qrimage":"
This is the debug of another Page without the URL on Page but available at Admin
{"status":"fail","code":"error:keyword","message":"Short URL 00027 already exists in database or is reserved","statusCode":200,"qrcimg":"http:\/\/doma.in\/user\/plugins\/inline-qrcode\/images\/qrcd41d8cd98f00b204e9800998ecf8427e.png","qrimage":"
This is my PHP Code
function shortyourls(){
global $smarty;
// Inputs
$shorturl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$signature = "123456789";
$siteurl = "http://doma.in";
$format = "json";
$Artikel = $smarty->get_template_vars('Artikel');
$title = http_build_query(array('title' => $Artikel->cName));
$keyword = preg_replace("/[^0-9,.]/", "", ($Artikel->cArtNr));
// Phases url
$short = file_get_contents($siteurl.'/yourls-api.php?signature='.$signature.'&action=shorturl&url='.$shorturl.'&format='.$format.'&keyword='.$keyword.'&'.$title);
$url=json_decode($short,TRUE);
$output = $url['shorturl'];
echo $output;
}
Any idea what is wrong?
Related
I want to make a redirect file using php which can add Affiliates tag automatically to all links. Like how it works https://freekaamaal.com/links?url=https://www.amazon.in/ .
If I open the above link it automatically add affiliate tag to the link and the final link which is open is this ‘https://www.amazon.in/?tag=freekaamaal-21‘ And same for Flipkart and many other sites also.
It automatically add affiliate tags to various links. For example amazon, Flipkart, ajio,etc.
I’ll be very thankful if anyone can help me regarding this.
Thanks in advance 🙏
Right now i made this below code but problem is that sometimes link have extra subdomain for example https://dl.flipkart.com/ or https://m.shopclues.com/ , etc for these type links it does not redirect from the array instead of this it redirect to default link.
<?php
$subid = isset($_GET['subid']) ? $_GET['subid'] : 'telegram'; //subid for external tracking
$affid = $_GET['url']; //main link
$parse = parse_url($affid);
$host = $parse['host'];
$host = str_ireplace('www.', '', $host);
//flipkart affiliate link generates here
$url_parts = parse_url($affid);
$url_parts['host'] = 'dl.flipkart.com';
$url_parts['path'] .= "/";
if(strpos($url_parts['path'],"/dl/") !== 0) $url_parts['path'] = '/dl'.rtrim($url_parts['path'],"/");
$url = $url_parts['scheme'] . "://" . $url_parts['host'] . $url_parts['path'] . (empty($url_parts['query']) ? '' : '?' . $url_parts['query']);
$afftag = "harshk&affExtParam1=$subid"; //our affiliate ID
if (strpos($url, '?') !== false) {
if (substr($url, -1) == "&") {
$url = $url.'affid='.$afftag;
} else {
$url = $url.'&affid='.$afftag;
}
} else { // start a new query string
$url = $url.'?affid='.$afftag;
}
$flipkartlink = $url;
//amazon link generates here
$amazon = $affid;
$amzntag = "subhdeals-21"; //our affiliate ID
if (strpos($amazon, '?') !== false) {
if (substr($amazon, -1) == "&") {
$amazon = $amazon.'tag='.$amzntag;
} else {
$amazon = $amazon.'&tag='.$amzntag;
}
} else { // start a new query string
$amazon = $amazon.'?tag='.$amzntag;
}
}
$amazonlink = $amazon;
$cueurl = "https://linksredirect.com/?subid=$subid&source=linkkit&url="; //cuelinks deeplink for redirection
$ulpsub = '&subid=' .$subid; //subid
$encoded = urlencode($affid); //url encode
$home = $cueurl . $encoded; // default link for redirection.
$partner = array( //Insert links here
"amazon.in" => "$amazonlink",
"flipkart.com" => "$flipkartlink",
"shopclues.com" => $cueurl . $encoded,
"aliexpress.com" => $cueurl . $encoded,
"ajio.com" => "https://ad.admitad.com/g/?ulp=$encoded$ulpsub",
"croma.com" => "https://ad.admitad.com/g/?ulp=$encoded$ulpsub",
"myntra.com" => "https://ad.admitad.com/g/?ulp=$encoded$ulpsub",
);
$store = array_key_exists($host, $partner) === false ? $home : $partner[$host]; //Checks if the host exists if not then redirect to your default link
header("Location: $store"); //Do not changing
exit(); //Do not changing
?>
Thank you for updating your answer with the code you have and explaining what the actual problem is. Since your reference array for the affiliate links is indexed by base domain, we will need to normalize the hostname to remove any possible subdomains. Right now you have:
$host = str_ireplace('www.', '', $host);
Which will do the job only if the subdomain is www., obviously. Now, one might be tempted to simply explode by . and take the last two components. However that'd fail with your .co.id and other second-level domains. We're better off using a regular expression.
One could craft a universal regular expression that handles all possible second-level domains (co., net., org.; edu.,...) but that'd become a long list. For your use case, since your list currently only has the .com, .in and .co.in domain extensions, and is unlikely to have many more, we'll just hard-code these into the regex to keep things fast and simple:
$host = preg_replace('#^.*?([^.]+\.)(com|id|co\.id)$#i', '\1\2', $host);
To explain the regex we're using:
^ start-of-subject anchor;
.*? ungreedy optional match for any characters (if a subdomain -- or a sub-sub-domain exists);
([^.]+\.) capturing group for non-. characters followed by . (main domain name)
(com|id|co\.id) capturing group for domain extension (add to list as necessary)
$ end-of-subject anchor
Then we replace the hostname with the contents of the capture groups that matched domain. and its extension. This will return example.com for www.example.com, foo.bar.example.com -- or example.com; and example.co.id for www.example.co.id, foo.bar.example.co.id -- or example.co.id. This should help your script work as intended. If there are further problems, please update the OP and we'll see what solutions are available.
This is my domain http://cdtr.cf it lands on index.php
Where I wrote some code which pulls the URL from URL box and trim its suffix to identify visitor's identity.
The Problem is when someone opening http://cdtr.cf/.... it shows error 404 page not found
while just http://cdtr.cd/ is working fine. All I need is When someone visit with http://cdtr.cf/.... they must be redirected to index.php and their request should be processed like http://cdtr.cf/index.php/.....
I want to keep the suffix anyhow for some purpose :-http://cdtr.cf/suffix.
It will be great if all this happen without any visible change in URL box.
Thanks in advance.
$link= (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=== 'on'? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo $link; //It is working fine on localhost but not when i put it live
This code will give you the rest of the url as per your requirement
<?php
$link = $_SERVER['REQUEST_URI'];
echo $link = ltrim($link, '/');
//if you want you can trim last / too using $link = rtrim($link, '/');
?>
If you want to get middle stuff like this yoursite.com/stuffs/removedthis
then you have to use below code
<?php
$link = $_SERVER['HTTP_HOST'];
$link .= $_SERVER['REQUEST_URI'];
$link = explode('/', $link);
echo $a = $link[1];
?>
Second example:
$link = "example.com/stuff/removethis/....blah";
$link = explode('/', $link);
echo $a = $link[1];
I have the following problem: I have a set of domains with the same url structure:
domain-a.com/london/
domain-b/london/
domain-c/london/
I want to do the following thing:
If you are on domain-a.com/london/, I want "related" links underneath pointing to domain-b.com/london/ and domain-c.com/london/
I want these links to appear automatically using the URL of the current page, remove the domain so that only the rest is left - in my example: /london/ and add the other domains in front of this.
I know I have to use echo $_SERVER['REQUEST_URI']; to get the rest of the URL but I don't know how to create a link using this function.
<?php
$url = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
function generateLink($url, $uri){
if(strpos($url,'domain-a.com') !== false){
$link = 'http://domain-b.com' . $uri;
return $link;
}else if(strpos($url,'domain-b.com') !== false){
$link = 'http://domain-c.com' . $uri;
return $link;
}else if(strpos($url,'domain-c.com') !== false){
$link = 'http://domain-a.com' . $uri;
return $link;
}
}
?>
Link
I'm currently working to make my own CRM website application and I followed Alex youtube tutorial which is the login/register using OOP.
In addition I need my index.php to be the dynamic content switcher, which I only include header and footer while the content load from a folder where it stores all the page. I believe the end result should be like www.example.com/index.php?page=profile
I look around and it seems like what I'm doing it's something similar to MVC pattern where index is the root file and all the content is loaded from view folder.
I managed to get everything done correctly but now instead of displaying the link like: www.example.com/user.php?name=jennifer
I wanted it to be www.example.com/user/name/jennifer
I try to look around phpacademy forum but the forum seems to be abandon, some search I managed to find a topic that relevant to what I want, but the code doesn't seems to be working and I got the same error with poster.
here is the code:
<?php
// Define the root of the site (this page should be in the root)
define('ROOT', rtrim(__DIR__, '/') . '/');
define('PAGES', ROOT . 'pages/');
// Define "safe" files that can be loaded
$safeFiles = ["login", "regiser", "profile", "changepassword"];
// Get URL
if(isset($_GET['page']) && !empty($_GET['page'])) {
$url = $_GET['page'];
} else {
$url = '/';
}
// Remove Path Traversal
$sanatize = array(
// Basic
'..', "..\\", '../', "\\",
// Percent encoding
'%2e%2e%2f', '%2e%2e/', '..%2f', '%2e%2e%5c', '%2e%2e', '..%5c', '%252e%252e%255c', '..%255c',
// UTF-8 encoding
'%c1%1c', '%c0%af', '..%c1%9c'
);
$url = str_replace($sanatize, '', $url);
// Prevent Null byte (%00)
// PHP 5.6 + should take care of this automatically, but PHP 5.0 < ....
$url = str_replace(chr(0), '', $url);
// Filter URL
$url = filter_var($url, FILTER_SANITIZE_URL);
// Remove any extra slashes
$url = rtrim($url, '/');
// Make lowercase url
$url = strtolower($url);
// Check current page
$path = PAGES . $url . '.php';
// If the file is in our safe array & exists, load it!
if(in_array($url, $safeFiles) && file_exists($path)) {
include($path);
} else {
echo "404: Page not found!";
}
I search around Google but I couldn't find a solution and I notice there were people asking in this forum as well hence I hope someone can assist me in this area.
For example, I have a referer URL. I want to redirect to a page according to the previous page's module.
There is a code snippet on this page. To get module and action of the previous page, you will use the referer:
$referer = sfContext::getInstance()->getRequest()->getReferer();
// you have to check if the referer is not empty and is a page of your site
....
// then get the module and action:
$url = parse_url($referer);
$path = trim($url['path'], '/');
if (!sfConfig::get('sf_no_script_name') && $pos = strpos($path, '/') )
{
$path = substr($path, $pos+1);
}
$params = sfContext::getInstance()->getRouting()->findRoute('/'.$path);
$module = $params['parameters']['module'];
$action = $params['parameters']['action'];