Jump to content

[SOLVED] PHP url branch??


ragsr@ix.netcom.com

Recommended Posts

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.

Link to comment
Share on other sites

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

}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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????

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.