andrewgarn Posted June 19, 2008 Share Posted June 19, 2008 I've been looking at ways to check urls are valid. This current one just gives an error every time. Requirements for the check are for a normal page to be valid, but a broken link and a 404 page NOT valid $url = 'http://www.google.co.uk''; echo $url; $valid = @fsockopen("$url", 80, $errno, $errstr, 30); if (!$valid) { // Error Message echo "URL not valid <br>"; ?><meta http-equiv="Refresh" content="1; URL=register.php"><? } else { Anyone? I will continue looking for solutions Link to comment https://forums.phpfreaks.com/topic/110964-solved-php-url-check-valid-or-404/ Share on other sites More sharing options...
andrewgarn Posted June 19, 2008 Author Share Posted June 19, 2008 This code appears to work to my specs. Can anyone confirm? <?php $url = 'www.google.co.uk'; $handle = @fopen($url,'r'); if($handle !== false){ echo 'Exists'; } else{ echo "Doesn't"; } ?> Link to comment https://forums.phpfreaks.com/topic/110964-solved-php-url-check-valid-or-404/#findComment-569319 Share on other sites More sharing options...
andrewgarn Posted June 19, 2008 Author Share Posted June 19, 2008 also could someone check this php function? I never seem to be good at ors in if functions... <?php if(!isset($_POST['username'] || $_POST['password'] || $email = $_POST['email'])) { echo "Please complete all fields"; } else { ?> It gives: Parse error: parse error, unexpected T_BOOLEAN_OR, expecting ',' or ')' in register.php on line 64 Link to comment https://forums.phpfreaks.com/topic/110964-solved-php-url-check-valid-or-404/#findComment-569331 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 You need to use a seperate isset() call for each variable: if(!isset($_POST['username']) || !isset($_POST['password']) || !isset($email = $_POST['email']))) { Link to comment https://forums.phpfreaks.com/topic/110964-solved-php-url-check-valid-or-404/#findComment-569335 Share on other sites More sharing options...
andrewgarn Posted June 19, 2008 Author Share Posted June 19, 2008 You need to use a seperate isset() call for each variable: if(!isset($_POST['username']) || !isset($_POST['password']) || !isset($email = $_POST['email']))) { thanks, that fixed the synatax, but it doesnt actually work. I submit the form with empty fields and it still gets past the if function <form name="login" method="post" action="register.php"> <table border="0" width="225" align="center"> <tr> <td width="219" bgcolor="#999999"> <p align="center"><font color="white"><span style="font-size:12pt;"><b>Registration</b></span></font></p> </td> </tr> <tr> <td width="219"> <table border="0" width="282" align="center"> <tr> <td width="116"><span style="font-size:10pt;">Username:</span></td> <td width="156"><input type="text" name="username"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Password:</span></td> <td width="156"><input type="password" name="password"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Email:</span></td> <td width="156"><input type="text" name="email" maxlength="100"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Enable</span></td> <td width="156"><SELECT NAME="track"><OPTION VALUE="Yes">Yes</OPTION><OPTION VALUE="No">No</OPTION></SELECT></td> </tr> <tr> <td width="116"> </td> <td width="156"> <p align="right"><input type="submit" name="submit" value="Submit"></p> </td> </tr> </table> </td> </tr> <tr> <td width="219" bgcolor="#999999"> </td> </tr> </table> </form> if(!isset($_POST['username']) || !isset($_POST['password']) || !isset($_POST['email'])) { echo "Please complete all fields"; } else { Link to comment https://forums.phpfreaks.com/topic/110964-solved-php-url-check-valid-or-404/#findComment-569349 Share on other sites More sharing options...
andrewgarn Posted June 19, 2008 Author Share Posted June 19, 2008 Made it work a different way, not good php, but it works if($_POST['username'] == NULL || $_POST['password'] == NULL || $_POST['email'] == NULL) Link to comment https://forums.phpfreaks.com/topic/110964-solved-php-url-check-valid-or-404/#findComment-569383 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.