Jump to content

Php Url Shortener Script...


ZhuXian
 Share

Recommended Posts

Heya,I recently made a url shortener script, and tested on xampp. It worked without a problem,so I decided to test it on a free host. (Zymic)How the script works:-Checks if text user inputs is a url-Makes a folder with a random name-Makes index.php inside of it with header to the link user input-Sends the short link to the user Now I'm running onto a problem. On the free host it creates a folder with a random name, but it doesn't create index.php inside of it.Anything knows what might be going wrong? =\ Thanks.

  • Like 1
Link to comment
Share on other sites

showing the code will be helpfull. not related to your problem but it sounds like you are creating one directory and file for each link entry. you can use single page to fetch each shorten url to original url and then redirecting it ,you dont need to overflow filesystem.

Link to comment
Share on other sites

I don't suggest creating a folder for each URL. If you learn about mod_rewrite, you can send all the URLs to the same file and have that file do the redirecting. (Check mod_rewrite on Google to see what I mean.)

Link to comment
Share on other sites

PHP will tell you exactly what the problem is with an error message if there was a problem and you have error messages enabled. If you aren't showing any error messages then that doesn't make it very easy to solve problems. The first step in solving a problem is to define what the actual problem is.

Link to comment
Share on other sites

showing the code will be helpfull. not related to your problem but it sounds like you are creating one directory and file for each link entry. you can use single page to fetch each shorten url to original url and then redirecting it ,you dont need to overflow filesystem.
index.php code
<?phperror_reporting(0);if ($_POST['url']){$url = strip_tags($_POST['url']);//Safe url$verification = strpos($url, "http://");//Check if there is http:// in text$verification2 = strpos($url, "www.");//Check if there is www. in textif($verification===0 || $verification2===0)//If http:// is equal to 0 or if www. is equal to 9 proceed{  $num = rand(1,50);  require("include/switch.php");//Require the code}  else  {   $invalid = '<img src="images/alert_info.png" id="alert_pos"/>';//If http:// is not equal to 0 or www. is not equal to 0 make an error variable  }} ?>

The include(Tried doing it with switch but its not working :S)

if ($num==1){$dir_name = str_shuffle("adgef34");if($verification===0)//If it has http://   {	mkdir($dir_name, 0777);//Make a directory with a random name  	$location = $dir_name."/index.php";//Location of the index.php	$open = fopen($location,'w');//Open index.php	$redirection = '<?php header("location:'.$url.'")?>';//Redirection	fwrite($open,$redirection);//Write the redirection  	$short_url = "http://www.skrati.iz.rs/".$dir_name;//Write the short url	$success = '<img src="images/alert_sucess_showurl.png" id="alert_pos" />	<input type="text" name="user_url" value="'.$short_url.'" readonly="readonly" size="30px" id="show_short_url"/>';//Success var   }   else if($verification2===0) //If it starts with www..   {	mkdir($dir_name, 0777);//Create dir with shuffle name  	$location = $dir_name."/index.php";//Lokacija redirekcije	$open = fopen($location,'w');//Open	$redirection = '<?php header("location:http://'.$url.'")?>';//Redirection	fwrite($open,$redirection);//Write redirection  	$short_url = "http://www.skrati.iz.rs/".$dir_name;//Write short url	$success = '<img src="images/alert_sucess_showurl.png" id="alert_pos" />	<input type="text" name="user_url" value="'.$short_url.'" readonly="readonly" size="30px" id="show_short_url"/>';//Success   }}

Im quite new with php so I don't know if the code is really good, but It was working on xampp.

I don't suggest creating a folder for each URL. If you learn about mod_rewrite, you can send all the URLs to the same file and have that file do the redirecting. (Check mod_rewrite on Google to see what I mean.)
Checked it, looks a bit confusing, but I will give it a shot. :D
PHP will tell you exactly what the problem is with an error message if there was a problem and you have error messages enabled. If you aren't showing any error messages then that doesn't make it very easy to solve problems. The first step in solving a problem is to define what the actual problem is.
Warning: fopen() [function.fopen]: SAFE MODE Restriction in effect. The script whose uid is 646546 is not allowed to access /www/zxq.net/s/k/r/skrati/htdocs/9y4fjtr owned by uid 2001 in /www/zxq.net/s/k/r/skrati/htdocs/include/switch.php on line 537Warning: fopen(9y4fjtr/index.php) [function.fopen]: failed to open stream: No such file or directory in /www/zxq.net/s/k/r/skrati/htdocs/include/switch.php on line 537Warning: fclose(): supplied argument is not a valid stream resource in /www/zxq.net/s/k/r/skrati/htdocs/include/switch.php on line 538Warning: fopen() [function.fopen]: SAFE MODE Restriction in effect. The script whose uid is 646546 is not allowed to access /www/zxq.net/s/k/r/skrati/htdocs/9y4fjtr owned by uid 2001 in /www/zxq.net/s/k/r/skrati/htdocs/include/switch.php on line 540Warning: fopen(9y4fjtr/index.php) [function.fopen]: failed to open stream: No such file or directory in /www/zxq.net/s/k/r/skrati/htdocs/include/switch.php on line 540Warning: fwrite(): supplied argument is not a valid stream resource in /www/zxq.net/s/k/r/skrati/htdocs/include/switch.php on line 542

Web host restrictions?

Edited by ZhuXian
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...