Page 1 of 1

Need a Lil Help

Posted: Tue Sep 16, 2008 8:55 pm
by wee493
(First off, Sorry I'm a n00b and i dont know PHP very well)

Hey, I'm testing with a lil PHP script. What I'm doing is a small web app like tinyurl.com. Right now it works good except for one thing. I would like for users to have to option of creating their own url (ex. instead of the randomly generated numbers/letters they can use their own text, like myurl.com/hello or myurl.com/coolcar or whatever).

Right now it just randomly generates some numbers/letters for their url or they can go to another page to enter their custom url. I would like to enable it to do both where if the user does not enter a custom url then it will randomly generate the url for them.

If you would like to see the site http://wiurl.com an for creating ur own url http://wiurl.com/index2

Below is The code

Code: Select all

<form name ="url" method="post" class="style2">
  <div align="center">Your Long URL:
    <input name="oldurl" type="text" size="28">
      <br>
      Wi URL: http://wiurl.com/
      <input name="newurl" type="text" size="21" />
      <br />
      <input type="submit" name="submit" value="Make it Wi">
      <br />
      Number of Wi URL's: 
      <?PHP // Hit counter //
      $count_my_page=("hitcounter.txt");
      $hits = file($count_my_page);
      $hits[0]++;
      $fp = fopen($count_my_page , "w");  // Open File
      fputs($fp , "$hits[0]");
      fclose($fp);
      echo $hits[0];
     // end pageviews   ?> 
  </div>
</form>
<span class="style2">
<?php
if ($_POST['submit']) {
$log=fopen("log1.html","a");
if( !$log ) {
} else {
  fwrite($log, "Date: " .date('l dS \of F Y h:i:s A') . ", IP:" . $REMOTE_ADDR . "<br>");
  fclose($log);
}
$rnd_url=chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,122)); // Later Add .rand(111,999)
$newurl = $_POST['newurl'];
$oldurl = $_POST['oldurl'];
$title= $_POST['title'];
$urlcloking= $_POST['urlcloking'];
$redirect = "<html><head><title>$title</title></head><body>
<iframe src='$oldurl' height='100%'  width='100%' frameborder='0'>
</script></body></html>";
 
if(file_exists("$newurl/index")) die("Please try again there was an error.");
mkdir("$newurl");
 
$filename = "$newurl/index";
$filename .= ".php";
$Content = "<META http-equiv='refresh' content='0;URL=$oldurl'>";
$handle = fopen($filename, 'x+');
fwrite($handle, $Content);
fclose($handle);
?>
<br>
</span>
<h2 class="style1"><marquee>Success!</marquee></h2>
<span class="style2">Your new URL is <a href=http://wiurl.com/<?php echo "$newurl"; ?>>http://wiurl.com/<?php echo"$newurl"; ?></a><br />
Copy your URL <input type="text" class="text" id="chi2" size="18" value="http://wiurl.com/<?php echo "$newurl"?>" onclick="this.select();" />

Re: Need a Lil Help

Posted: Wed Sep 17, 2008 5:40 pm
by wee493
bump

Re: Need a Lil Help

Posted: Wed Sep 17, 2008 6:26 pm
by josh
So what's your question?

Re: Need a Lil Help

Posted: Thu Sep 18, 2008 9:20 pm
by wee493
wee493 wrote: I would like to enable it to do both where if the user does not enter a custom url then it will randomly generate the url for them and if they do enter a URL for it not to randomly generate one

Re: Need a Lil Help

Posted: Fri Sep 19, 2008 7:58 am
by josh
I would like to make more money and travel the world.

I would also like for you to take some more initiative on your own and maybe ask a specific question.

You might look into using maybe a conditional. Maybe you might even have to learn about the isset() or the trim() function. Perhaps you will have to pull up a manual page and read about the different string functions PHP offers at your disposal.