I have a proxy script and I want that the user inserts http:// before he surfs, but let's say he doesn't enter it I want it to be added, but if he doesn't I don't want to end up with http://http://www.website.com
So please can anyone help me? I have a text box in index.html to write the URL and then a php script to surf the website in a frame.
Can anyone help please?
Thanks.
What about putting "http://" as standard value in the inputbox? Then the user will probably right the URL after the "http://". It can easily be done by setting a value-attribute at the tag.
Then of course some users will probably remove the "http://", so you still have to find away of checking for "http://". For this you can use the PHP-function strpos. The function will return false if the string didn't got found, and else the position.Code:<input ... value="http://" />
Code:$input = $_GET["input_from_user"]; $haystack = strtolower($input); $needle = "http://"; $position = strpos($haystack, $needle); // Check if "http://" wasn't in the page if($position === false) $page = "http://" . $haystack; else $page = $haystack; // Continue with the job to be done
I have already done the one with the value, now I will try the other bit of code..
Will let you know, I'm trying it.
*EDIT* Wow man, it works perfectly. if no URL is given it always displays that the URL is wrong, Thanks! I had to edit it a little bit, although I don't know any PHP, but I figured it out as I know some programming. Anyways thanks!!
Last edited by TcM; 05-16-2007 at 07:41 AM.
I'm glad, you could use it.
To make the validation for the input even more secure, try look into some Regular Expressions. It's a short, clean - but also a bit hard way to validate your input in only a line, or maybe a little more. There's tons of information about Regular Expressions "out there", and also for many different languages.
A good place to start, would be here:
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
Last edited by TcM; 05-16-2007 at 07:57 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks