ZhuXian Posted January 12, 2012 Share Posted January 12, 2012 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. Link to comment Share on other sites More sharing options...
birbal Posted January 12, 2012 Share Posted January 12, 2012 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 More sharing options...
Ingolme Posted January 12, 2012 Share Posted January 12, 2012 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 More sharing options...
justsomeguy Posted January 12, 2012 Share Posted January 12, 2012 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 More sharing options...
ZhuXian Posted January 12, 2012 Author Share Posted January 12, 2012 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. 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? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 12, 2012 Share Posted January 12, 2012 Right, the host has the safe mode option on and it doesn't look like they'll let you access those directories through PHP. Link to comment Share on other sites More sharing options...
ZhuXian Posted January 13, 2012 Author Share Posted January 13, 2012 Right, the host has the safe mode option on and it doesn't look like they'll let you access those directories through PHP. Ok, could you suggest a free host for me to test on? Link to comment Share on other sites More sharing options...
Mudsaf Posted January 13, 2012 Share Posted January 13, 2012 I suggest free host: 000webhost.comOffers 1500MB disc space + alot of more Link to comment Share on other sites More sharing options...
dzhax Posted January 15, 2012 Share Posted January 15, 2012 you already have xampp why dont you get a dyndns or no-ip redirect to your pc and run it at home? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.