De hele tijd krijg ik de volgende melding als ik me url heb geshort op mijn site. Ik heb de script al bij verschillende host's getest maar steeds krijg ik deze melding:
Warning: Cannot modify header information - headers already sent by (output started at /home/saliox/domains/anoniem/linkshort/index.php:8) in /home/saliox/domains/anoniem/public_html/linkshort/index.php on line 138
waar nu anoniem staat staatdan normaal me site. (even weg gehaald in verband met privacy.)
wat er op lijn 8 staat:
<meta name="keywords" content="link, links" />
wat er op lijn 138 staat:
header("Location: {$urls[$id]}");
exit;
dit is helaas bij meerdere scripts zodra ik ze in een layout zet.
Kan iemand me even snel helpen?
script afkomstig van Spyka.net
Hier nog even het gehele script:
PHP Code:
<?php
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Short URL script</title>
<?php
/*
*
* script by spyka Webmaster - www.spyka.net
* version 1.0.2
* copyright (c) 2008 spyka Web Group
* license http://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0
* support: http://www.spyka.net/forums
*
*/
/*
location of file to store URLS
*/
$file = 'urls.txt';
/*
use mod_rewrite: 0 - no or 1 - yes
*/
$use_rewrite = 1;
/*
language/style/output variables
*/
$l_url = 'URL';
$l_nourl = '<strong>No URL supplied</strong>';
$l_yoururl = '<strong>Your short url:</strong>';
$l_invalidurl = '<strong>Invalid URL supplied.</strong>';
$l_createurl = 'Make shorter!';
//////////////////// NO NEED TO EDIT BELOW ////////////////////
if(!is_writable($file) || !is_readable($file))
{
die('Cannot write or read from file. Please CHMOD the url file (urls.txt) by default to 777 and make sure it is uploaded.');
}
$action = trim($_GET['id']);
$action = (empty($action) || $action == '') ? 'create' : 'redirect';
$valid = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
$output = '';
if($action == 'create')
{
if(isset($_POST['create']))
{
$url = trim($_POST['url']);
if($url == '')
{
$output = $l_nourl;
}
else
{
if(eregi($valid, $url))
{
$fp = fopen($file, 'a');
fwrite($fp, "{$url}\r\n");
fclose($fp);
$id = count(file($file));
$dir = dirname($_SERVER['PHP_SELF']);
$filename = explode('/', $_SERVER['PHP_SELF']);
$filename = $filename[(count($filename) - 1)];
$shorturl = ($use_rewrite == 1) ? "http://{$_SERVER['HTTP_HOST']}{$dir}/{$id}" : "http://{$_SERVER['HTTP_HOST']}{$dir}/{$filename}?id={$id}";
$output = "{$l_yoururl} <a href='{$shorturl}'>{$shorturl}</a>";
}
else
{
$output = $l_invalidurl;
}
}
}
}
if($action == 'redirect')
{
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location: {$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
//////////////////// FEEL FREE TO EDIT BELOW ////////////////////
?>
<!-- start html output -->
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p class="response"><?=$output?></p>
<p>
<input id="s-url" type="text" name="url" />
</p>
<p>
<input type="submit" class="button" name="create" value="<?=$l_createurl?>" />
</p>
</form>
<p> </p>
<!-- end html output -->
</body>
</html>
<?php
ob_end_flush();
?>
- Cannot send header?
-
18-08-2010, 19:25 #1
- Berichten
- 416
- Lid sinds
- 14 Jaar
Cannot send header?
-
-
18-08-2010, 19:35 #2
- Berichten
- 433
- Lid sinds
- 17 Jaar
deze foutmelding krijg je zodra je voor je header(); reeds output naar de browser stuurt.
Oftewel, zodra jij html code neerzet, dan stuur je reeds output naar de browser. Wanneer dan later de header() functie gebruikt wordt, krijg je en foutmelding.
Eerst alle php code, en daarna pas de html is hier de oplossing.
-
18-08-2010, 19:38 #3
- Berichten
- 416
- Lid sinds
- 14 Jaar
Ik snap het even niet dus je bedoeld, dat ik eerst alle php scripts op me site plaats en daarna html?
-
18-08-2010, 19:40 #4gast Guest
-
18-08-2010, 19:41 #5
- Berichten
- 257
- Lid sinds
- 15 Jaar
Kijk in ieder geval voor de zekerheid dat er helemaal niets (ook geen spaties) voor de php open tag staan.
De eerste karakters die in je scriptfile staan moeten '<?php' zijn.
-
18-08-2010, 19:49 #6
- Berichten
- 91
- Lid sinds
- 15 Jaar
je moet zorgen dat die header() word aangeroepen voordat je met de <html> begint.
-
18-08-2010, 19:52 #7
- Berichten
- 416
- Lid sinds
- 14 Jaar
Misscien een beetje dom van me maar, ik snap het nog steeds niet, kijk als je 12 jaar bent snap je niet alles lijkt mij. (ik weet ik ben jong)
Met op zonder ' '
'<?php'
en heb gekeken op spaties enzo maar tot nu toe geen resultaat
Heb zonet overal de spaties weg gehaalt, maar nog geen resultaat (ik bedoel hiermee bijvoorbeeld:
Voor:
PHP Code:header("Location: {$urls[$id]}");
exit;
}
else
{
die('Script error');
Na
header("Location:{$urls[$id]}");
exit;
}
else
{
die('Script error');Laatst aangepast door Jan Moorman : 18-08-2010 om 19:57
-
18-08-2010, 19:56 #8
- Berichten
- 91
- Lid sinds
- 15 Jaar
Zet dit is boven je <html>:
if($action == 'redirect')
{
$file = 'urls.txt';
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location: {$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
Zal denk ik wel werken
-
18-08-2010, 20:00 #9
- Berichten
- 416
- Lid sinds
- 14 Jaar
Je bedoeld dus:
if($action == 'redirect')
{
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location:{$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
vervangen door:
if($action == 'redirect')
{
$file = 'urls.txt';
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location: {$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
Als je dat bedoelde heeft het dus niet gewerkt
-
18-08-2010, 20:15 #10
- Berichten
- 257
- Lid sinds
- 15 Jaar
Probeer dit eens:
PHP Code:<?php
ob_start();
/*
*
* script by spyka Webmaster - www.spyka.net
* version 1.0.2
* copyright (c) 2008 spyka Web Group
* license http://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0
* support: http://www.spyka.net/forums
*
*/
/*
location of file to store URLS
*/
$file = 'urls.txt';
/*
use mod_rewrite: 0 - no or 1 - yes
*/
$use_rewrite = 1;
/*
language/style/output variables
*/
$l_url = 'URL';
$l_nourl = '<strong>No URL supplied</strong>';
$l_yoururl = '<strong>Your short url:</strong>';
$l_invalidurl = '<strong>Invalid URL supplied.</strong>';
$l_createurl = 'Make shorter!';
//////////////////// NO NEED TO EDIT BELOW ////////////////////
if(!is_writable($file) || !is_readable($file))
{
die('Cannot write or read from file. Please CHMOD the url file (urls.txt) by default to 777 and make sure it is uploaded.');
}
$action = trim($_GET['id']);
$action = (empty($action) || $action == '') ? 'create' : 'redirect';
$valid = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
$output = '';
if(
$action == 'create')
{
if(isset($_POST['create']))
{
$url = trim($_POST['url']);
if($url == '')
{
$output = $l_nourl;
}
else
{
if(eregi($valid, $url))
{
$fp = fopen($file, 'a');
fwrite($fp, "{$url}\r\n");
fclose($fp);
$id = count(file($file));
$dir = dirname($_SERVER['PHP_SELF']);
$filename = explode('/', $_SERVER['PHP_SELF']);
$filename = $filename[(count($filename) - 1)];
$shorturl = ($use_rewrite == 1) ? "http://{$_SERVER['HTTP_HOST']}{$dir}/{$id}" : "http://{$_SERVER['HTTP_HOST']}{$dir}/{$filename}?id={$id}";
$output = "{$l_yoururl} <a href='{$shorturl}'>{$shorturl}</a>";
}
else
{
$output = $l_invalidurl;
}
}
}
}
if(
$action == 'redirect')
{
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location: {$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
ob_end_flush();
?>
//////////////////// FEEL FREE TO EDIT BELOW ////////////////////
<!-- start html output -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Short URL script</title>
</head>
<body>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p class="response"><?=$output?></p>
<p>
<input id="s-url" type="text" name="url" />
</p>
<p>
<input type="submit" class="button" name="create" value="<?=$l_createurl?>" />
</p>
</form>
<p> </p>
<!-- end html output -->
</body>
</html>
-
19-08-2010, 07:54 #11
- Berichten
- 416
- Lid sinds
- 14 Jaar
dan krijg ik op de home dit stukje code te zien: //////////////////// FEEL FREE TO EDIT BELOW ////////////////////
en als ik op maak short druk dan krijg ik dit weer:
Warning: Cannot modify header information - headers already sent by (output started at /home/saliox/domains/anoniem/public_html/linkshort/index.php:8) in /home/saliox/domains/anoniem/public_html/linkshort/index.php on line 132
Misscien handig voor jullie:
Hier de hele index.php:
PHP Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>linkshort.nl</title>
<meta name="keywords" content="link, links" />
<meta name="description" content="Url verkleinen" />
<meta name="keyphrases" content="short" />
<meta name="Classification" content="Links" />
<meta http-equiv="content-language" content="nl-nl" />
<meta name="robots" content="index, follow" />
<meta name="revisit-after" content="1 days" />
<meta name="copyright" content="jan" />
<meta name="author" content="Jan" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="js/cufon.js" type="text/javascript"></script>
<script src="js/Calibri_400.font.js" type="text/javascript"></script>
<script src="js/global.js" type="text/javascript"></script>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
Cufon.replace('h1');
</script>
</head>
<body>
<div id="wrapper">
<div id="wrapperTop">
</div>
<div id="wrapperLogo">
</div>
<div id="wrapperMain">
<div class="content">
<h1>Welkom op Twitshort</h1>
<p>In onderhoud.</p>
<p> </p>
</div><?php
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Short URL script</title>
<?php
/*
*
* script by spyka Webmaster - www.spyka.net
* version 1.0.2
* copyright (c) 2008 spyka Web Group
* license http://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0
* support: http://www.spyka.net/forums
*
*/
/*
location of file to store URLS
*/
$file = 'urls.txt';
/*
use mod_rewrite: 0 - no or 1 - yes
*/
$use_rewrite = 1;
/*
language/style/output variables
*/
$l_url = 'URL';
$l_nourl = '<strong>No URL supplied</strong>';
$l_yoururl = '<strong>Your short url:</strong>';
$l_invalidurl = '<strong>Invalid URL supplied.</strong>';
$l_createurl = 'Make shorter!';
//////////////////// NO NEED TO EDIT BELOW ////////////////////
if(!is_writable($file) || !is_readable($file))
{
die('Cannot write or read from file. Please CHMOD the url file (urls.txt) by default to 777 and make sure it is uploaded.');
}
$action = trim($_GET['id']);
$action = (empty($action) || $action == '') ? 'create' : 'redirect';
$valid = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
$output = '';
if($action == 'create')
{
if(isset($_POST['create']))
{
$url = trim($_POST['url']);
if($url == '')
{
$output = $l_nourl;
}
else
{
if(eregi($valid, $url))
{
$fp = fopen($file, 'a');
fwrite($fp, "{$url}\r\n");
fclose($fp);
$id = count(file($file));
$dir = dirname($_SERVER['PHP_SELF']);
$filename = explode('/', $_SERVER['PHP_SELF']);
$filename = $filename[(count($filename) - 1)];
$shorturl = ($use_rewrite == 1) ? "http://{$_SERVER['HTTP_HOST']}{$dir}/{$id}" : "http://{$_SERVER['HTTP_HOST']}{$dir}/{$filename}?id={$id}";
$output = "{$l_yoururl} <a href='{$shorturl}'>{$shorturl}</a>";
}
else
{
$output = $l_invalidurl;
}
}
}
}
if($action == 'redirect')
{
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location:{$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
?>
<!-- start html output -->
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p class="response"><?=$output?></p>
<p>
<input id="s-url" type="text" name="url" />
</p>
<p>
<input type="submit" class="button" name="create" value="<?=$l_createurl?>" />
</p>
</form>
<p> </p>
<!-- end html output -->
</body>
</html>
<?php
ob_end_flush();
?>
<h1> </h1>
<div id="copyright">
<p align="center">Copyright Twitshort</div>
</div>
<div id="wrapperBottom">
</div>
</div>
</body>
</html>
-
19-08-2010, 09:44 #12
- Berichten
- 257
- Lid sinds
- 15 Jaar
Zo werkt hij bij mij wel.
(ik gebruik dan voor redirect: index.php?id=3 (bijvoorbeeld)
Ik neem aan dat jij daarvoor rewriterules hebt.
Zoals eerder al gezegd: je mag niets eerder naar de browser verzenden als je zelf de headers wilt versturen! Dat doe je wel als je eerst wat html code verstuurt en vervolgens 'header("Location:{$urls[$id]}");' aanroept. Die ob_start() verandert daar niets aan volgens mij want die houdt alleen de output van het PHP gedeelte vast en niet de output die buiten de php tags omgaat.
Bovendien lijkt je code wat slordig want onderaan sluit je meerdere malen de body en html af.
PHP Code:<?php
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Short URL script</title>
<?php
/*
*
* script by spyka Webmaster - www.spyka.net
* version 1.0.2
* copyright (c) 2008 spyka Web Group
* license http://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0
* support: http://www.spyka.net/forums
*
*/
/*
location of file to store URLS
*/
$file = 'urls.txt';
/*
use mod_rewrite: 0 - no or 1 - yes
*/
$use_rewrite = 1;
/*
language/style/output variables
*/
$l_url = 'URL';
$l_nourl = '<strong>No URL supplied</strong>';
$l_yoururl = '<strong>Your short url:</strong>';
$l_invalidurl = '<strong>Invalid URL supplied.</strong>';
$l_createurl = 'Make shorter!';
//////////////////// NO NEED TO EDIT BELOW ////////////////////
if(!is_writable($file) || !is_readable($file))
{
die('Cannot write or read from file. Please CHMOD the url file (urls.txt) by default to 777 and make sure it is uploaded.');
}
$action = trim($_GET['id']);
$action = (empty($action) || $action == '') ? 'create' : 'redirect';
$valid = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
$output = '';
if(
$action == 'create')
{
if(isset($_POST['create']))
{
$url = trim($_POST['url']);
if($url == '')
{
$output = $l_nourl;
}
else
{
if(eregi($valid, $url))
{
$fp = fopen($file, 'a');
fwrite($fp, "{$url}\r\n");
fclose($fp);
$id = count(file($file));
$dir = dirname($_SERVER['PHP_SELF']);
$filename = explode('/', $_SERVER['PHP_SELF']);
$filename = $filename[(count($filename) - 1)];
$shorturl = ($use_rewrite == 1) ? "http://{$_SERVER['HTTP_HOST']}{$dir}/{$id}" : "http://{$_SERVER['HTTP_HOST']}{$dir}/{$filename}?id={$id}";
$output = "{$l_yoururl} <a href='{$shorturl}'>{$shorturl}</a>";
}
else
{
$output = $l_invalidurl;
}
}
}
}
if(
$action == 'redirect')
{
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location:{$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
ob_end_flush();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>linkshort.nl</title>
<meta name="keywords" content="link, links" />
<meta name="description" content="Url verkleinen" />
<meta name="keyphrases" content="short" />
<meta name="Classification" content="Links" />
<meta http-equiv="content-language" content="nl-nl" />
<meta name="robots" content="index, follow" />
<meta name="revisit-after" content="1 days" />
<meta name="copyright" content="jan" />
<meta name="author" content="Jan" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="js/cufon.js" type="text/javascript"></script>
<script src="js/Calibri_400.font.js" type="text/javascript"></script>
<script src="js/global.js" type="text/javascript"></script>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
Cufon.replace('h1');
</script>
</head>
<body>
<div id="wrapper">
<div id="wrapperTop">
</div>
<div id="wrapperLogo">
</div>
<div id="wrapperMain">
<div class="content">
<h1>Welkom op Twitshort</h1>
<p>In onderhoud.</p>
<p> </p>
</div>
<!-- start html output -->
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p class="response"><?=$output?></p>
<p>
<input id="s-url" type="text" name="url" />
</p>
<p>
<input type="submit" class="button" name="create" value="<?=$l_createurl?>" />
</p>
</form>
<p> </p>
<!-- end html output -->
<h1> </h1>
<div id="copyright">
<p align="center">Copyright Twitshort</div>
</div>
<div id="wrapperBottom">
</div>
</div>
</body>
</html>
-
19-08-2010, 10:09 #13
- Berichten
- 158
- Lid sinds
- 14 Jaar
Als hij gewoon alles voor <?php weggooid... Je moet gewoon dat van Ruud overnemen. Hij heeft inderdaad dubbele <html> en dergelijke, omdat hij hiermee ook begint voor de PHP code. Neem gewoon de code van Ruud, en prop je code pas erin NA de PHP.
-
19-08-2010, 10:23 #14
- Berichten
- 416
- Lid sinds
- 14 Jaar
Heel erg bedankt ramon, ik wou net een reactie plaatsen dat ik het niet snapte.
Maar het is nu toch gelukt :)
Mvg Jan
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic