0

I'm developing app for Facebook. Here when user open application should be checked If user already exists in database. I think I will use $_SESSIONto pass user's Id to checkIfExsists.php

So my FacebookGetId.php looks like:

<?php
...
$id = $user_profile['id'];
$_SESSION['id'] = $id;
?>

So $id for now is i.e. '12345' I just don't know how to make automatically redirect to checkIfExsists.php to check If that Id already exsists in database.

It should be something like: When application is launched, It should take User's Id and automatically redirect to checkIfExsists.phpand pass that Id.

If user exists checkIfExsists.php should redirect user to application.php, if not exists - It should redirect to registration.php

3
  • If user exists checkIfExsists.php should redirect user to application.php, if not exists - It should redirect to registration.php Commented Mar 24, 2015 at 8:55
  • You can use http_redirect("relpath", array("name" => "value"), true, HTTP_REDIRECT_PERM);. for more information Visit thislink, it will help you. Commented Mar 24, 2015 at 9:06
  • Duplicate of How to check Facebook User's ID already exists before lauching app? Commented Mar 24, 2015 at 12:21

4 Answers 4

6

Use the header function

<?php
...
$id = $user_profile['id'];
$_SESSION['id'] = $id;
header('Location: checkIfExsists.php?id='.$id);
?>

on the checkIfExsists.php get the variable with

$id = $_GET["id"];

That would solve your problem the way you want it to be solved, but, this isn´t neccesarilly the way it should be solved, maybe inside checkIfExists.php should be a class instead of structured code with a public function to check existance checkExistance, so you will then just need:

include_once(checkIfExists.php);
$check = new checker();
$exists = $check->checkExistance($id) ;

this way you do not have to be jumping between files and you can have a better way to re-use code, regards.

Sign up to request clarification or add additional context in comments.

5 Comments

No need to pass the ID along with the URL, the ID is allready set in a SESSION
then the whole FacebookGetId.php is obsolet, cause all to do is to start a session on the checkIfExsist.php and get the id with $_SESSION['id']
Thank you for an answer, but It returning me blank page, It shouldn't be blank, in checkIfExsists.php I'm using session_start(); $id = $_SESSION['id']; echo $id; and in top of page trying to print errors: ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); but still empty, why can I get this problem?
I don't know what you do with the $id on the checkIfExsists.php but when you want to validate is i guess you check it against a Database. So when you verify that the id is existant you should implent a if function with another header. For example: if($id == $validate_id) { header('Location: application.php'); } else { header('Location: registration.php'); }
Thank you, that worked for me. I missed ; that's why was blank screen.
3

Use this:

<?php
 session_start();
 $id = $user_profile['id'];
 $_SESSION['id'] = $id;
 header('Location: checkIfExsists.php');
?>

And on the checkIfExsists.php page, retrieve the variable so:

<?php
 session_start();
 $id = $_SESSION['id'];
?>

1 Comment

Thank you for an answer, but It returning me blank page, It shouldn't be blank, in checkIfExsists.php I'm using session_start(); $id = $_SESSION['id']; echo $id; and in top of page trying to print errors: ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); but still empty, why can I get this problem?
1

Use header('Location:url_of_your_page.php?fbid='.$id). php header function

FacebookGetId.php

<?php
    ...
    $id = $user_profile['id'];
    $_SESSION['id'] = $id;
    header('Location:checkIfExsists.php?fbid='.$id)
?>

2 Comments

Thank you for an answer, but It returning me blank page, It shouldn't be blank, in checkIfExsists.php I'm using session_start(); $id = $_SESSION['id']; echo $id; and in top of page trying to print errors: ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); but still empty, why can I get this problem?
@StanislovasKalašnikovas may be your $_SESSION['id'] has an empty value, try adding a string to your echo, eg. echo "Facebook ID : ".$_SESSION['id'].
1

you can do it via GET and header for example :)

header('Location: checkIfExists.php?userID=12345');

in checkIfExists.php

echo $_GET["userID"]

or in checkIfExists.php just start sessions a load ID from session :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.