-1
'''<?php
$str = "sachintendulkar";

for ($i=0, $c=strlen($str); $i<$c; $i++)
    $str[$i] = (rand(0, 100) > 50
        ? strtoupper($str[$i])
        : strtolower($str[$i]));



echo "$str";

header("location.href='www.google.com/$str'")
?>'''

i want to use this code

in my script which change ramndomly capital small but im getting erron in scrip t help me

Poco user
  • 1
  • 1
  • Share the code that causes the error.... The above will not create any error. its working fine – Indra Kumar S Jun 06 '21 at 03:52
  • ` PHP Test 50 ? strtoupper($str[$i]) : strtolower($str[$i])); echo "$str"; header('Refresh: 0; URL=http://yoursite.com/$str'); ?> ` – Poco user Jun 06 '21 at 03:58
  • 1
    You might want to add the code from the comment above to your question using the edit button. The formatting will be much easier to read. – morric Jun 06 '21 at 05:48

1 Answers1

1

Remove the echo "$str";. Once a script outputs text (like echo "$str";) you can no longer set headers. Headers must be set before any output is sent.

For the redirection part, you probably want something like:

header("Location: https://www.google.com/$str");

Note that html in your script is also "output" so all header calls must also come before any html. With that in mind, the full file might look like the below. Its worth noting here though that the html is a bit useless given the user will always be redirected to another page.

<?php

$str = "xyz";
for ($i = 0, $c = strlen($str); $i < $c; $i++) {
    $str[$i] = (rand(0, 100) > 50 ? strtoupper($str[$i]) : strtolower($str[$i]));
}
header("Location: http://www.google.com/$str"); 
?>

<html>
<head>
    <title>PHP Test</title>
</head>
<body>
</body>
</html>
Wesley Smith
  • 19,401
  • 22
  • 85
  • 133