ragsr@ix.netcom.com Posted October 26, 2009 Share Posted October 26, 2009 Functionally, using PHP, I'm doing a test of login input submitted by a user via an html form in a file located at http://..../loginregister.php. If that test is successfull, I want to branch to http://..../index.php without further user interaction. QUESTION #1: Can PHP located in a file accessed via, say, url A branch or jump to code in a new file, say accessed via url B? If so, please give me a code example. QUESTION #2: Can HTML be used to accomplish the same thing? I'm pretty sure the answer to this is no thus the first question. Thx. in advance for you help. Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/ Share on other sites More sharing options...
lemmin Posted October 26, 2009 Share Posted October 26, 2009 Are you trying to redirect the user? You could just use header(): header("Location: index.php"); Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944865 Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 26, 2009 Author Share Posted October 26, 2009 lemmin....I'm not trying to redirect the user. The user has submitted his login and I want the code to first test that login against my database then go to the second url if the test is passed or return to the first url if it fails. Thx. Bob G. Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944871 Share on other sites More sharing options...
lemmin Posted October 26, 2009 Share Posted October 26, 2009 I think you'll have to be more specific because that sounds just like redirecting to me. Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944879 Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 26, 2009 Author Share Posted October 26, 2009 lemmin....got it. Thx. I'm not familiar with the "header" function but I'll read about it now and get back to you. Bob G. Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944883 Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 26, 2009 Author Share Posted October 26, 2009 lemmin....QUESTION: Am I on the right track...here's what I did... The header function looks good but it didn't work out of the chute. I inserted the header in the appropriate function (see copy below) but when I used a correct login in for the html input for I've done for user login the code took me to the correct function and then, within it, to the header (appx. line 17 in code sample below...I removed the full url for privacy in the copy below) and I got the warning below. THE WARNING: Warning: Cannot modify header information - headers already sent by (output started at http://....../loginregister.php:44) in http://....loginregister.php on line 54 Note: Line 54 is the header line Note: Line 44 is just a dbug echo... "echo "MATCH :"."$match"."<br>" ; To implement the header, I inserted a single line in the function below. It is about the 17th line from the top and I edited out the true url for privacy purposes. THE CODE: function updateloggedin ($match, $FBluseremailaddress ) { //echo "UPDATELOGGEDIN"."<br>" ; echo "MATCH :"."$match"."<br>" ; echo "FBl:"."$FBluseremailaddress" ; //Connect to the Database connecttodatabase () ; $tablename ="FBTableUserInput" ; //mysql_query("select FBloggedin from $tablename where FBemail==$FBluseremailaddress " ) ; if ($match=="1") { //mysql_query("select FBloggedin from $tablename where FBemail==$FBluseremailaddress " ) ; mysql_query("update $tablename set FBloggedin='1' where FBemail='$FBluseremailaddress' " ) ; header ("location: http://www.apps.facebook.com/....canvas/" ) ; } if ($match=="0") { //mysql_query("select FBloggedin from $tablename where FBemail==$FBluseremailaddress " ) ; mysql_query("update $tablename set FBloggedin='0' where FBemail='$FBluseremailaddress' " ) ; } //THE BRACKET BELOW IS THE END OF THE FUNCTION } Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944902 Share on other sites More sharing options...
JAY6390 Posted October 26, 2009 Share Posted October 26, 2009 To use the header function, you need to use it before ANY output. Make sure you don't output anything before it With regards to sending your data from one page to the next, I'd suggest using sessions and passing it along that way Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944905 Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 26, 2009 Author Share Posted October 26, 2009 Jay6390...thx for the input. I just noted the following line in my PHP reference which corresponds to your input. " ...it is important to remember that HTTP headers must be sent to the browser before any text or HTML content." With that statement I have a problem because I must precede the test of the user inputs with an html form to get the inputs in the first place!! I'll start trying to figure that one out now. Re. "sending your data". I don't have a problem with that. I either use query strings or a form's hidden or visible variables. Thx. again. Bob G. Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944921 Share on other sites More sharing options...
JAY6390 Posted October 26, 2009 Share Posted October 26, 2009 You should do all your script logic before anything else, then do your outputs. logic never relies on output Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944930 Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 26, 2009 Author Share Posted October 26, 2009 JAY6390....what do you mean by "outputs"??? HTML? Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944934 Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 26, 2009 Author Share Posted October 26, 2009 Problem not solved by the PHP header function: Per inputs from lemin and JAY6390, I've tested the PHP header function and don't see how it can solve my problem (please refer to original post). The PHP header function seems to be intended for Redirects. It must be placed ahead of any Output or HTML so it does not work in my case. QUESTION: What other PHP function or coding technique can I use to solve the problem in my original post???? Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-944999 Share on other sites More sharing options...
MadTechie Posted October 27, 2009 Share Posted October 27, 2009 header() would be the correct approach, however it can be difficult when you first start using it, with that said I noticed that you output html before the redirect, this is a NO NO, when using headers.. here's an example, This is a good use, of header if you have a single script that has a log-in form, that posts to itself and if the details are correct it, redirect to a profile page. <?php if(isset($_POST['submit']){ //connect to DB and check username and password if($detailsValid) { header("Location: profile.php"); //nothing out putted so this works fine exit(); }else{ echo "Wrong username or password<br>"; } } ?> HTML FORM HERE (always after the header) okay, now in your example you have echo "MATCH :"."$match"."<br>" ; echo "FBl:"."$FBluseremailaddress" ; this is output thus the header will fail, you have a few options, but your second question was QUESTION #2: Can HTML be used to accomplish the same thing? I'm pretty sure the answer to this is no thus the first question. Well you could use JavaScript, but YES you can use HTML, with the refresh meta tag example <html> <head> <title>Redirecting</title> <META http-equiv="refresh" content="5;URL=profile.php"> </head> <body> You will be redirected in 5 seconds <br /> <a href="profile.php">redirect now</a> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-945098 Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 27, 2009 Author Share Posted October 27, 2009 MadTechie....Just got home late and won't be able to try your suggestions out but they sound right on the money. Many thanks for the inputs. I especially like your pointer on meta refresh tag. I'll try all of your techniques sometime tomorrow and post a reply when I'm done. Thanks again. PS...I'm working on prototypes of two websites that are related and which I want to, eventually, launch publicly. At some point, I'll need help in converting the prototypes into more robust industrial strength versions. Do you do contract work fitting that description? If so, feel free to contact me by email. My PHP Freaks name is my email address. Thanks again. Bob G. Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-945179 Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 27, 2009 Author Share Posted October 27, 2009 MadTechie, Awesome input. MANY THANKS!! Your html suggestion has me moving towards a solution. I want to eliminate the user step of clicking on the redirect link that your code requires but I can certainly get my app working ok even with that step being taken by the user. I didn't know about the "meta" class of html operations and will research them to see if I can get to my final objective. I consider this question answered and will mark the question answered. Thanks again. Bob G. Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-945566 Share on other sites More sharing options...
MadTechie Posted October 27, 2009 Share Posted October 27, 2009 The code sample above would redirect automatically after 5 seconds even without user interaction, if you change <META http-equiv="refresh" content="5;URL=profile.php"> to <META http-equiv="refresh" content="1;URL=profile.php"> the page will redirect after 1 seconds to profile.php Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-945568 Share on other sites More sharing options...
ragsr@ix.netcom.com Posted October 27, 2009 Author Share Posted October 27, 2009 Techie....got it!!! THANKS AGAIN. Bob G. Quote Link to comment https://forums.phpfreaks.com/topic/179089-solved-php-url-branch/#findComment-945572 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.