I have a problem with php header redirect. I already spent hours trying to fix it.
The problem doesn’t occur when the bit.ly api is not used in the script, I have no clue why.
<?php
if (strlen($_GET['url']) > 26) {
$shortenedURL = $_GET['url'];
if (isset($_GET['login']) && isset($_GET['apikey'])) {
$shortenedURL = file_get_contents('http://api.bit.ly/v3/shorten?format=txt&login='.urlencode($_GET['login']).'&apiKey='.$_GET['apikey'].'&uri='.urlencode($_GET['url']));
}
else {
$shortenedURL = file_get_contents('http://icbrd.net/shorten.php?longurl='.$_GET['url']);
}
if (strlen($shortenedURL) > 0) {
header( 'Location: icebird://compose?status='.$shortenedURL.'%20' );
exit();
}
else {
header( 'Location: icebird://compose?status='.$_GET['url'].'%20' );
exit();
}
}
else {
header( 'Location: icebird://compose?status='.$_GET['url'].'%20' );
exit();
}
?>
I hope you can help me, as this is driving me crazy.
Regards
You really need to get the hang of ways to debug.
Use a variable to hold the url and use that as the parameter to file_get_contents. This way you can output/debug the value and see what is going wrong.
If the URL looks good then request the URL manually and/or output/debug the $shortenedURL variable to see the contents – it could be an error instead of what you are expecting.
It’s near impossible for us to debug your code since we don’t know the values to all your variables.