I need a page to redirect to another page with out a set url. I tried using the way of combining strings...

Code:
<?php

srand((double)microtime()*10000); 
$number = rand(0,100);

$random[1] = "****";
$random[2] = "****";
$random[3] = "****";
$random[4] = "****";
$random[5] = "****";
$random[6] = "****";
$random[7] = "****";
$random[8] = "****";
$random[9] = "****";
$random[10] = "****";
$random[11] = "****";
$random[12] = "****";
$random[13] = "****";
$random[14] = "****";
$random[15] = "****";

$n = rand(1,15);

$word = $random['$n'];

$item = $HTTP_GET_VARS['item'];

$url = "file.php?id=" . $random['$n'] . $number . "&item=" . $item . "";

header("location:" . $url);

?>

...but in the end it will only come out as:
    file.php?id=###&item=blah

instead of:
    file.php?id=****###&item=blah
In other words, it does'nt put the random word into the url, it pretty much ignores it. it worked when I typed it in, but I tried it automaticly and it did'nt work Confused .
Please help.
    I did not release the whole code so, all my random variables = ****, but in the real code there all differant.
Never mind, I found the problem. Thanks for all that help, and in all a matter of 1 minute!
Laughing
Wow, we're getting so good at this, we can do it telepathically now... Shock

Code:

<?php

srand((double)microtime()*10000);
$number = rand(0,100);

$random = array( "****", "****",  "****", "****", "****", "****", "****",  "****",  "****", "****"  ,"****", "****", "****", "****", "****");

$n = rand(0,15);

$word = $random['$n'];

$item = $HTTP_GET_VARS['item'];

$url = "file.php?id=" . $random['$n'] . $number . "&item=" . $item . "";

header("location:" . $url);

?>

Slight optimization... saves you... about 13 lines of code Razz

Code:
<?php

srand((double)microtime()*10000);
$number = rand(0,100);

$random = array( "****", "****",  "****", "****", "****", "****", "****",  "****",  "****", "****"  ,"****", "****", "****", "****", "****");

$n = rand(0,15);

$url = "file.php?id=" . $random['$n'] . $number . "&item=" . $HTTP_GET_VARS['item'] . "";

header("location:" . $url);

?>
Two more gone. Smile

Code:

<?php

srand((double)microtime()*10000);

$random = array( "****", "****",  "****", "****", "****", "****", "****",  "****",  "****", "****"  ,"****", "****", "****", "****", "****");

$n = rand(0,15);

$url = "file.php?id=" . $random[$n] . rand(0, 100) . "&item=" . $HTTP_GET_VARS['item'] . "";

header("location:" . $url);

?>

Fixed a bug that would have prevented it from working properly Wink

EDIT: and got rid of another line Wink
you know, fewer lines don't necessarily mean its faster.... (this ain't TI-Basic) - and 99% of the time it won't result in a smaller program either

White Space == Good (when used properly) in a computer program. For example, it would be better programming practice to break that array up into multiple lines, like such


Code:
array("*****", "*****", "*****", "*****",
      "*****", "*****", "*****", "*****");


So that the array elements start at the same column, and don't exceed 80 characters per line.
Hmm... true

Generally I do use some whitespace for readibility.. it's not always a huge priority, and depends on what the code is.. I use less white space in MySQL queries and more in arrays (usually, with arrays, i put one element per line)
I'm terrible with whitespace in PHP; I hardly ever put lines between thinks, except perhaps different subfunctions.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement